line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Math::Tutor::Role::Natural; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
712
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
4
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
App::Math::Tutor::Role::Natural - role for natural numbers |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=cut |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
7
|
use Moo::Role; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
13
|
1
|
|
|
1
|
|
446
|
use App::Math::Tutor::Numbers; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
232
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.005'; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
0
|
|
|
sub _check_natural_number { $_[0]->value >= 2 } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
requires "format"; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _guess_natural_number |
22
|
|
|
|
|
|
|
{ |
23
|
0
|
|
|
0
|
|
|
my $max_val = $_[0]->format; |
24
|
0
|
|
|
|
|
|
my $value = int( rand($max_val) ); |
25
|
0
|
|
|
|
|
|
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
|
0
|
|
|
0
|
1
|
|
my ( $self, $amount ) = @_; |
39
|
0
|
|
|
|
|
|
my @result; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
while ( $amount-- ) |
42
|
|
|
|
|
|
|
{ |
43
|
0
|
|
|
|
|
|
my $nn; |
44
|
|
|
|
|
|
|
do |
45
|
0
|
|
|
|
|
|
{ |
46
|
0
|
|
|
|
|
|
$nn = $self->_guess_natural_number; |
47
|
|
|
|
|
|
|
} while ( !_check_natural_number($nn) ); |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
push @result, $nn; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
@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; |