Algorithm-BestChoice
view release on metacpan or search on metacpan
inc/Module/AutoInstall.pm view on Meta::CPAN
my @args = @_ or return;
my $core_all;
print "*** $class version " . $class->VERSION . "\n";
print "*** Checking for Perl dependencies...\n";
my $cwd = Cwd::cwd();
$Config = [];
my $maxlen = length(
(
sort { length($b) <=> length($a) }
grep { /^[^\-]/ }
map {
ref($_)
? ( ( ref($_) eq 'HASH' ) ? keys(%$_) : @{$_} )
: ''
}
map { +{@args}->{$_} }
grep { /^[^\-]/ or /^-core$/i } keys %{ +{@args} }
)[0]
);
inc/Module/Install.pm view on Meta::CPAN
sub _version ($) {
my $s = shift || 0;
my $d =()= $s =~ /(\.)/g;
if ( $d >= 2 ) {
# Normalise multipart versions
$s =~ s/(\.)(\d{1,3})/sprintf("$1%03d",$2)/eg;
}
$s =~ s/^(\d+)\.?//;
my $l = $1 || 0;
my @v = map {
$_ . '0' x (3 - length $_)
} $s =~ /(\d{1,3})\D?/g;
$l = $l . '.' . join '', @v if @v;
return $l + 0;
}
sub _cmp ($$) {
_version($_[0]) <=> _version($_[1]);
}
# Cloned from Params::Util::_CLASS
inc/Module/Install/Makefile.pm view on Meta::CPAN
for my $subdir (@_) {
push @$subdirs, $subdir;
}
}
sub clean_files {
my $self = shift;
my $clean = $self->makemaker_args->{clean} ||= {};
%$clean = (
%$clean,
FILES => join ' ', grep { length $_ } ($clean->{FILES} || (), @_),
);
}
sub realclean_files {
my $self = shift;
my $realclean = $self->makemaker_args->{realclean} ||= {};
%$realclean = (
%$realclean,
FILES => join ' ', grep { length $_ } ($realclean->{FILES} || (), @_),
);
}
sub libs {
my $self = shift;
my $libs = ref $_[0] ? shift : [ shift ];
$self->makemaker_args( LIBS => $libs );
}
sub inc {
lib/Algorithm/BestChoice.pm view on Meta::CPAN
has options => qw/is ro required 1 isa ArrayRef/, default => sub { [] };
sub add {
my $self = shift;
my %given = @_;
$given{matcher} = $given{match} unless exists $given{matcher};
$given{ranker} = $given{rank} unless exists $given{ranker};
my ($matcher, $ranker) = @given{ qw/matcher ranker/ };
if ($ranker && ! ref $ranker && $ranker eq 'length') {
if (! ref $matcher) {
$ranker = defined $matcher ? length $matcher : 0;
}
else {
die "Trying to rank by length, but given not-scalar matcher $matcher";
}
}
$matcher = Algorithm::BestChoice::Matcher->parse( $matcher );
$ranker = Algorithm::BestChoice::Ranker->parse( $ranker );
my $option = Algorithm::BestChoice::Option->new( matcher => $matcher, ranker => $ranker, value => $given{value} );
push @{ $self->options }, $option;
}
t/01-basic.t view on Meta::CPAN
is( $result[0], 'banana' );
@result = $choice->best( 'xyzzy' );
is( @result, 3 );
is( $result[0], 'cherry' );
@result = $choice->best( 'xyzzyxyz' );
is( @result, 2 );
is( $result[0], 'banana' );
$choice->add( value => 'cranberry', rank => 'length', match => 'xyzzy' );
@result = $choice->best();
is( @result, 2 );
is( $result[0], 'banana' );
@result = $choice->best( 'xyzzy' );
is( @result, 4 );
is( $result[0], 'cranberry' );
@result = $choice->best( 'xyzzyxyz' );
( run in 0.590 second using v1.01-cache-2.11-cpan-65fba6d93b7 )