File Coverage

blib/lib/App/Math/Tutor/Role/Natural.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 32 32 100.0


line stmt bran cond sub pod time code
1             package App::Math::Tutor::Role::Natural;
2              
3 1     1   823 use warnings;
  1         2  
  1         34  
4 1     1   6 use strict;
  1         3  
  1         30  
5              
6             =head1 NAME
7              
8             App::Math::Tutor::Role::Natural - role for natural numbers
9              
10             =cut
11              
12 1     1   6 use Moo::Role;
  1         1  
  1         8  
13 1     1   419 use App::Math::Tutor::Numbers;
  1         3  
  1         344  
14              
15             our $VERSION = '0.004';
16              
17 184     184   4132 sub _check_natural_number { return $_[0]->value >= 2 }
18              
19             requires "format";
20              
21             sub _guess_natural_number
22             {
23 62     62   94 my $max_val = $_[0]->format;
24 62         81 my $value = int( rand($max_val) );
25 62         1215 return NatNum->new( value => $value );
26             }
27              
28             =head1 METHODS
29              
30             =head2 get_natural_number
31              
32             Returns as many natural numbers as requested. Does Factory :)
33              
34             =cut
35              
36             sub get_natural_number
37             {
38 90     90 1 113 my ( $self, $amount ) = @_;
39 90         87 my @result;
40              
41 90         165 while ( $amount-- )
42             {
43 180         170 my $nn;
44             do
45 180         178 {
46 184         2920 $nn = $self->_guess_natural_number;
47             } while ( !_check_natural_number($nn) );
48              
49 180         489 push @result, $nn;
50             }
51              
52 90         249 return @result;
53             }
54              
55             =head1 LICENSE AND COPYRIGHT
56              
57             Copyright 2010-2014 Jens Rehsack.
58              
59             This program is free software; you can redistribute it and/or modify it
60             under the terms of either: the GNU General Public License as published
61             by the Free Software Foundation; or the Artistic License.
62              
63             See http://dev.perl.org/licenses/ for more information.
64              
65             =cut
66              
67             1;