Algorithm-BestChoice
view release on metacpan or search on metacpan
lib/Algorithm/BestChoice.pm view on Meta::CPAN
$rank = $option->rank( $key );
die "Got an undefined rank from a ranker" unless defined $rank;
die "Got a non-numeric rank ($rank) from a ranker" unless looks_like_number $rank;
}
push @tally, Algorithm::BestChoice::Result->new( rank => $rank, value => $option->value );
}
}
return @tally;
}
# TODO: Test for this multi-key ranker
# TODO: Probably want to give different weights to different keys!
sub best {
my $self = shift;
my @tally = map { $self->_best( $_ ) } @_ ? map { ref $_ eq 'ARRAY' ? @$_ : $_ } @_ : (undef);
@tally = sort { $b->rank <=> $a->rank } @tally;
@tally = map { $_->value } @tally;
return wantarray ? @tally : $tally[0];
}
=head1 AUTHOR
Robert Krimen, C<< <rkrimen at cpan.org> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-algorithm-bestchoice at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Algorithm-BestChoice>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Algorithm::BestChoice
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Algorithm-BestChoice>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/Algorithm-BestChoice>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/Algorithm-BestChoice>
=item * Search CPAN
L<http://search.cpan.org/dist/Algorithm-BestChoice/>
=back
=head1 ACKNOWLEDGEMENTS
=head1 COPYRIGHT & LICENSE
Copyright 2009 Robert Krimen, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
'"Purple is a fruit"'; # End of Algorithm::BestChoice
( run in 1.155 second using v1.01-cache-2.11-cpan-df04353d9ac )