mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Additions to the Perl family of languages (#4066)
* Mainly fixing problems with Perl heuristics And also adding a little bit of text to the README file to help with local use and test. * Adds new sample * Adds a couple of samples more, not represented before * Moves installation intructions to CONTRIBUTING.md Refs #2309 and also changes github.com to an uniform capitalization. * Correcting error. Great job, CI * Moving another file * Adds samples and new checks for perl/perl6 * Stupid mistake * Changing regex for perl5 vs perl6 Initial suggestion by @pchaigno, slightly changed to eliminate false positives such as "classes" or "modules" at the beginning of a line in the =pod BTW, it would be interesting to just eliminate these areas for language detection. * Eliminates Rexfile from Perl6 And adds .pod6 * Followup to #2709 I just found I had this sitting here, so I might as well follow instructions to fix it. * Adds example for pod6 * Eliminates .pod because it's its own language * Removes bad directory * Reverting changes that were already there * Restored CONTRIBUTING.md from head I see installation of cmake is advised in README.md * Eliminates `.pod6` To leave way for #3366 or succeeding PRs. * Removed by request, since we're no longer adding this extension * Sorting by alphabetical order filenames * Moved from sample to test fixtures
This commit is contained in:
committed by
Colin Seymour
parent
7b9ec3d1b3
commit
a9ff59aef5
@@ -3386,6 +3386,8 @@ Perl:
|
||||
- ".psgi"
|
||||
- ".t"
|
||||
filenames:
|
||||
- Makefile.PL
|
||||
- Rexfile
|
||||
- ack
|
||||
- cpanfile
|
||||
interpreters:
|
||||
@@ -3409,8 +3411,6 @@ Perl 6:
|
||||
- ".pm"
|
||||
- ".pm6"
|
||||
- ".t"
|
||||
filenames:
|
||||
- Rexfile
|
||||
interpreters:
|
||||
- perl6
|
||||
aliases:
|
||||
|
||||
100
samples/Perl/Any.pm
Normal file
100
samples/Perl/Any.pm
Normal file
@@ -0,0 +1,100 @@
|
||||
use strict; #-*-cperl-*-
|
||||
use warnings;
|
||||
|
||||
use lib qw( ../../../../lib );
|
||||
|
||||
=encoding utf8
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Algorithm::Evolutionary::Fitness::Any - Façade for any function so that it can be used as fitness
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use Algorithm::Evolutionary::Utils qw( string_decode )
|
||||
|
||||
sub squares {
|
||||
my $chrom = shift;
|
||||
my @values = string_decode( $chrom, 10, -1, 1 );
|
||||
return $values[0] * $values[1];
|
||||
}
|
||||
|
||||
my $any_eval = new Algorithm::Evolutionary::Fitness::Any \&squares;
|
||||
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Turns any subroutine or closure into a fitness function. Useful mainly
|
||||
if you want results cached; it's not really needed otherwise.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=cut
|
||||
|
||||
package Algorithm::Evolutionary::Fitness::Any;
|
||||
|
||||
use Carp;
|
||||
|
||||
use base 'Algorithm::Evolutionary::Fitness::Base';
|
||||
|
||||
our $VERSION = '3.2';
|
||||
|
||||
=head2 new( $function )
|
||||
|
||||
Assigns default variables
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $self = { _function => shift || croak "No functiona rray" };
|
||||
bless $self, $class;
|
||||
$self->initialize();
|
||||
return $self;
|
||||
}
|
||||
|
||||
=head2 apply( $individual )
|
||||
|
||||
Applies the instantiated problem to a chromosome. It is actually a
|
||||
wrapper around C<_apply>.
|
||||
|
||||
=cut
|
||||
|
||||
sub apply {
|
||||
my $self = shift;
|
||||
my $individual = shift || croak "Nobody here!!!";
|
||||
$self->{'_counter'}++;
|
||||
return $self->_apply( $individual );
|
||||
}
|
||||
|
||||
=head2 _apply( $individual )
|
||||
|
||||
This is the one that really does the stuff. It applies the defined
|
||||
function to each individual. Itis cached for efficiency.
|
||||
|
||||
=cut
|
||||
|
||||
sub _apply {
|
||||
my $self = shift;
|
||||
my $individual = shift || croak "Nobody here!";
|
||||
my $chrom = $individual->Chrom();
|
||||
my $cache = $self->{'_cache'};
|
||||
if ( $cache->{$chrom} ) {
|
||||
return $cache->{$chrom};
|
||||
}
|
||||
my $result = $self->{'_function'}->($chrom);
|
||||
if ( (scalar $chrom ) eq $chrom ) {
|
||||
$cache->{$chrom} = $result;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
=head1 Copyright
|
||||
|
||||
This file is released under the GPL. See the LICENSE file included in this distribution,
|
||||
or go to http://www.fsf.org/licenses/gpl.txt
|
||||
|
||||
=cut
|
||||
|
||||
"What???";
|
||||
20
samples/Perl/filenames/Makefile.PL
Normal file
20
samples/Perl/filenames/Makefile.PL
Normal file
@@ -0,0 +1,20 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
use ExtUtils::MakeMaker;
|
||||
|
||||
WriteMakefile(
|
||||
NAME => 'Algorithm::Evolutionary::Simple',
|
||||
AUTHOR => 'JJ Merelo <jj@merelo.net>',
|
||||
VERSION_FROM => 'lib/Algorithm/Evolutionary/Simple.pm',
|
||||
ABSTRACT_FROM => 'lib/Algorithm/Evolutionary/Simple.pm',
|
||||
LICENSE => 'gpl',
|
||||
EXE_FILES => [ 'script/simple-EA.pl', 'script/maxones.pl'],
|
||||
PREREQ_PM => {
|
||||
'Test::More' => 0,
|
||||
'Carp' => 0,
|
||||
'Exporter' => 0,
|
||||
'Sort::Key::Top' => 0
|
||||
},
|
||||
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
|
||||
clean => { FILES => 'Algorithm-Evolutionary-Simple-*' },
|
||||
);
|
||||
9
samples/Perl/filenames/Rexfile
Normal file
9
samples/Perl/filenames/Rexfile
Normal file
@@ -0,0 +1,9 @@
|
||||
use Rex -feature => ['1.0'];
|
||||
|
||||
user "eleccionesugr";
|
||||
group eleccionesugr => "elecciones-ugr.cloudapp.net";
|
||||
|
||||
desc "Install perlbrew";
|
||||
task "perlbrew", group => "eleccionesugr", sub {
|
||||
};
|
||||
|
||||
9
test/fixtures/Perl 6/chromosome.pl
vendored
Normal file
9
test/fixtures/Perl 6/chromosome.pl
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
class Chromosome {
|
||||
has Seq $.chromosome is rw;
|
||||
has $.fitness is rw;
|
||||
|
||||
}
|
||||
|
||||
my $len = 32;
|
||||
my $this-chromosome = Chromosome.new( chromosome => map( { rand >= 0.5 ?? True !! False }, 1..$len ) );
|
||||
say $this-chromosome.chromosome();
|
||||
Reference in New Issue
Block a user