Acme-Affinity

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

    - Attempt to appease cpantesters...

0.0112 2022-02-16 22:09:44
    - Specify Math::BigInt minimum version.

0.0111 2020-07-14 16:40:37
    - Fix documentation grammar.

0.0110 2020-07-14 14:16:28
    - Improve documentation.
    - Make all the attributes required.
    - Clean up test a bit.
    - Use an algorithm instead of hardcoded "you" answers in the eg/q_and_a program.

0.0109 2020-03-22 00:08:27
    - Improved the eg/q_and_a program.

0.0108 2020-03-21 23:45:08
    - Improve documentation.
    - Add the eg/q_and_a program to illustrate how this module might be used.

LICENSE  view on Meta::CPAN


General Provisions

(10)  Any use, modification, and distribution of the Standard or
Modified Versions is governed by this Artistic License. By using,
modifying or distributing the Package, you accept this license. Do not
use, modify, or distribute the Package, if you do not accept this
license.

(11)  If your Modified Version has been derived from a Modified
Version made by someone other than you, you are nevertheless required
to ensure that your Modified Version complies with the requirements of
this license.

(12)  This license does not grant you the right to use any trademark,
service mark, tradename, or logo of the Copyright Holder.

(13)  This license includes the non-exclusive, worldwide,
free-of-charge patent license to make, have made, use, offer to sell,
sell, import and otherwise transfer the Package with respect to any
patent claims licensable by the Copyright Holder that are necessarily

lib/Acme/Affinity.pm  view on Meta::CPAN

use Math::BigRat ();
use Moo;
use strictures 2;
use namespace::clean;


has questions => (
    is       => 'ro',
    isa      => sub { die 'Not an ArrayRef' unless ref($_[0]) eq 'ARRAY' },
    default  => sub { [] },
    required => 1,
);


has importance => (
    is      => 'ro',
    isa     => sub { die 'Not a HashRef' unless ref($_[0]) eq 'HASH' },
    default => sub {
        {
            'irrelevant'         => 0,
            'a little important' => 1,
            'somewhat important' => 10,
            'very important'     => 50,
            'mandatory'          => 250,
        }
    },
    required => 1,
);


has me => (
    is       => 'ro',
    isa      => sub { die 'Not an ArrayRef' unless ref($_[0]) eq 'ARRAY' },
    default  => sub { [] },
    required => 1,
);


has you => (
    is       => 'ro',
    isa      => sub { die 'Not an ArrayRef' unless ref($_[0]) eq 'ARRAY' },
    default  => sub { [] },
    required => 1,
);


sub score {
    my $self = shift;

    my $me_score  = _score( $self->me, $self->you, $self->importance );
    my $you_score = _score( $self->you, $self->me, $self->importance );

    my $m = Math::BigRat->new($me_score);



( run in 0.340 second using v1.01-cache-2.11-cpan-0a6323c29d9 )