line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Math::Tutor::Role::PolyExercise; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
702
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
App::Math::Tutor::Role::PolyExercise - role for for exercises with polynom |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=cut |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use Moo::Role; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
13
|
1
|
|
|
1
|
|
296
|
use MooX::Options; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
with "App::Math::Tutor::Role::Exercise", "App::Math::Tutor::Role::Poly"; |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
544
|
use Scalar::Util qw/looks_like_number/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
450
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.005'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head2 format |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Specifies format of factor per term |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
option format => ( |
30
|
|
|
|
|
|
|
is => "ro", |
31
|
|
|
|
|
|
|
doc => "specifies format of natural number as factor per term", |
32
|
|
|
|
|
|
|
long_doc => "Allow specifying the format of the natural number " |
33
|
|
|
|
|
|
|
. "whereby any digit is typed with 'n' as placeholder:\n\n" |
34
|
|
|
|
|
|
|
. "\t--format 5nnn\n\n" |
35
|
|
|
|
|
|
|
. "creates natural numbers from -5999 .. 5999.\n\n" |
36
|
|
|
|
|
|
|
. "Default: 100", |
37
|
|
|
|
|
|
|
isa => sub { |
38
|
|
|
|
|
|
|
defined( $_[0] ) |
39
|
|
|
|
|
|
|
and !looks_like_number( $_[0] ) |
40
|
|
|
|
|
|
|
and $_[0] !~ m,^\d?n+?$, |
41
|
|
|
|
|
|
|
and die("Invalid format"); |
42
|
|
|
|
|
|
|
}, |
43
|
|
|
|
|
|
|
coerce => sub { |
44
|
|
|
|
|
|
|
defined( $_[0] ) or return 100; |
45
|
|
|
|
|
|
|
looks_like_number( $_[0] ) and int( $_[0] ) == $_[0] and return $_[0]; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my ($fmtv) = ( $_[0] =~ m,^(\d?n+)?$, ); |
48
|
|
|
|
|
|
|
my $startv = "1"; |
49
|
|
|
|
|
|
|
$fmtv =~ s/^(\d)(.*)/$2/ and $startv = $1; |
50
|
|
|
|
|
|
|
my $maxv = $startv . "0" x length($fmtv); |
51
|
|
|
|
|
|
|
$maxv; |
52
|
|
|
|
|
|
|
}, |
53
|
|
|
|
|
|
|
default => sub { 100 }, |
54
|
|
|
|
|
|
|
format => "s", |
55
|
|
|
|
|
|
|
short => "f", |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 max_power |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Specifies format of exponent |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
option max_power => ( |
65
|
|
|
|
|
|
|
is => "ro", |
66
|
|
|
|
|
|
|
doc => "specifies the highest exponent", |
67
|
|
|
|
|
|
|
long_doc => "Allow specifying the format of the polynom " . "by using the higest exponent.\n\n" . "Default: 2", |
68
|
|
|
|
|
|
|
isa => sub { |
69
|
|
|
|
|
|
|
defined( $_[0] ) |
70
|
|
|
|
|
|
|
and !looks_like_number( $_[0] ) |
71
|
|
|
|
|
|
|
and die("Invalid exponent"); |
72
|
|
|
|
|
|
|
int( $_[0] ) == $_[0] |
73
|
|
|
|
|
|
|
or die("Invalid exponent"); |
74
|
|
|
|
|
|
|
}, |
75
|
|
|
|
|
|
|
default => sub { 2 }, |
76
|
|
|
|
|
|
|
format => "i", |
77
|
|
|
|
|
|
|
short => "e", |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 probability |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Specifies probability per term in % |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
option probability => ( |
87
|
|
|
|
|
|
|
is => "ro", |
88
|
|
|
|
|
|
|
doc => "specifies probability per term", |
89
|
|
|
|
|
|
|
long_doc => "Allow specifying the probability of each term of the polynom\n\n" . "Default: 80", |
90
|
|
|
|
|
|
|
isa => sub { |
91
|
|
|
|
|
|
|
defined( $_[0] ) |
92
|
|
|
|
|
|
|
and !looks_like_number( $_[0] ) |
93
|
|
|
|
|
|
|
and die("Invalid probability"); |
94
|
|
|
|
|
|
|
$_[0] <= 0 |
95
|
|
|
|
|
|
|
and $_[0] > 100 |
96
|
|
|
|
|
|
|
and die("Invalid probability"); |
97
|
|
|
|
|
|
|
}, |
98
|
|
|
|
|
|
|
default => sub { 95 }, |
99
|
|
|
|
|
|
|
format => "f", |
100
|
|
|
|
|
|
|
short => "p", |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Copyright 2010-2014 Jens Rehsack. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
108
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
109
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |