line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Math::Tutor::Role::Exercise; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
452
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
App::Math::Tutor::Role::Exercise - basic role for getting exercises |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=cut |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
3
|
use Moo::Role; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
13
|
1
|
|
|
1
|
|
277
|
use MooX::Options; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
449
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
63
|
|
16
|
1
|
|
|
1
|
|
4
|
use Cwd qw(abs_path getcwd); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
43
|
|
17
|
1
|
|
|
1
|
|
4
|
use File::Spec (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
13
|
|
18
|
1
|
|
|
1
|
|
242
|
use File::ShareDir (); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Template (); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.005'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 quantity |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Specifies number of calculations to generate |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
option quantity => ( |
32
|
|
|
|
|
|
|
is => "ro", |
33
|
|
|
|
|
|
|
doc => "Specifies number of exercises to generate", |
34
|
|
|
|
|
|
|
long_doc => "Specify number of exercises to generate. In " |
35
|
|
|
|
|
|
|
. "case of several kind of exercises, \$quantity exercises " |
36
|
|
|
|
|
|
|
. "are generated per kind.", |
37
|
|
|
|
|
|
|
format => "i", |
38
|
|
|
|
|
|
|
short => "n", |
39
|
|
|
|
|
|
|
default => sub { 15 }, |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 exercises |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Lazy hash containing the exercises to fill into the template. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Expected attribute: |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=over 4 |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item section |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
The caption of the section containing the challenges. The solutions section |
53
|
|
|
|
|
|
|
will reuse the section caption prepended by I<Solution:>. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item caption |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Table caption for challenges table. The solutions table will be prepended |
58
|
|
|
|
|
|
|
by the word I<Solution>. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=item label |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Label of the table containing the challenges - the solutions table will |
63
|
|
|
|
|
|
|
be the given label prepended by I<solution>. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item header |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
List of table headers - one header per column |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item challenges |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
List of challenges to exercise |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item solutions |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
List of solutions of challenges |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item usepackages |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
List of additional package names to pass to \usepackage |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item headeritems |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
List of additional lines to put to document header |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=back |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
has exercises => ( |
90
|
|
|
|
|
|
|
is => "lazy", |
91
|
|
|
|
|
|
|
# requires _build_exercises |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 output_name |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Lazy string representing the basename without extension of the output |
97
|
|
|
|
|
|
|
file. The default builder returns the names of all commands in chain |
98
|
|
|
|
|
|
|
joined with empty string. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
has output_name => ( |
103
|
|
|
|
|
|
|
is => "lazy", |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _build_output_name |
107
|
|
|
|
|
|
|
{ |
108
|
|
|
|
|
|
|
join( "", map { $_->command_name || "" } @{ $_[0]->command_chain } ); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 output_type |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Lazy string representing the extension of the output file. The default |
114
|
|
|
|
|
|
|
builder returns 'pdf'. Permitted to be set via MooX::Options. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
option output_type => ( |
119
|
|
|
|
|
|
|
is => "lazy", |
120
|
|
|
|
|
|
|
doc => "Specifies the output type (tex, pdf, ps)", |
121
|
|
|
|
|
|
|
format => "s", |
122
|
|
|
|
|
|
|
short => "t", |
123
|
|
|
|
|
|
|
); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub _build_output_type { 'pdf' } |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 output_location |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Lazy string representing the location of the output file in file system. The |
130
|
|
|
|
|
|
|
default builder returns the full qualified path name to the current working |
131
|
|
|
|
|
|
|
directory. Permitted to be set via MooX::Options. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
option output_location => ( |
136
|
|
|
|
|
|
|
is => "lazy", |
137
|
|
|
|
|
|
|
doc => "Specifies the output location", |
138
|
|
|
|
|
|
|
format => "s", |
139
|
|
|
|
|
|
|
short => "o", |
140
|
|
|
|
|
|
|
); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub _build_output_location { abs_path(getcwd) } |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 REQUIRED ATTRIBUTES |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 template_filename |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
The basename of the template file for processing to get the exercises. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
requires "template_filename"; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub execute |
155
|
|
|
|
|
|
|
{ |
156
|
|
|
|
|
|
|
my $self = shift; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
my $exercises = $self->exercises; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
my $sharedir = File::ShareDir::dist_dir("App-Math-Tutor"); |
161
|
|
|
|
|
|
|
my $ttcpath = File::Spec->catfile( $sharedir, $self->template_filename . ".tt2" ); |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
my $template = Template->new( |
164
|
|
|
|
|
|
|
{ |
165
|
|
|
|
|
|
|
ABSOLUTE => 1, |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
); |
168
|
|
|
|
|
|
|
my $rc = $template->process( |
169
|
|
|
|
|
|
|
$ttcpath, |
170
|
|
|
|
|
|
|
{ |
171
|
|
|
|
|
|
|
exercises => $exercises, |
172
|
|
|
|
|
|
|
output => { |
173
|
|
|
|
|
|
|
format => $self->output_type, |
174
|
|
|
|
|
|
|
}, |
175
|
|
|
|
|
|
|
}, |
176
|
|
|
|
|
|
|
File::Spec->catfile( $self->output_location, join( ".", $self->output_name, $self->output_type ) ), |
177
|
|
|
|
|
|
|
); |
178
|
|
|
|
|
|
|
$rc or croak( $template->error() ); |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
0; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Copyright 2010-2014 Jens Rehsack. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
188
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
189
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
1; |