File Coverage

blib/lib/App/Math/Tutor/Role/PowerExercise.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package App::Math::Tutor::Role::PowerExercise;
2              
3 1     1   515 use warnings;
  1         2  
  1         31  
4 1     1   4 use strict;
  1         2  
  1         27  
5              
6             =head1 NAME
7              
8             App::Math::Tutor::Role::PowerExercise - role for exercises in power mathematics
9              
10             =cut
11              
12 1     1   3 use Moo::Role;
  1         1  
  1         7  
13 1     1   257 use MooX::Options;
  1         2  
  1         6  
14              
15             with "App::Math::Tutor::Role::Exercise", "App::Math::Tutor::Role::Power";
16              
17             our $VERSION = '0.005';
18              
19             =head1 ATTRIBUTES
20              
21             =head2 format
22              
23             Specifies format of basis^exponent
24              
25             =cut
26              
27             option format => (
28             is => "ro",
29             doc => "specifies format of basis^exponent",
30             long_doc => "Allow specifying the format of the basis^exponent "
31             . "whereby any digit is typed with 'n' as placeholder:\n\n"
32             . "\t--format 5nnn^nn\n\n"
33             . "creates power between 5999^99 and 0002^02.\n\n"
34             . "Default: 20^10",
35             isa => sub {
36             defined( $_[0] )
37             and !ref $_[0]
38             and $_[0] !~ m,^\d?n+(?:\^\d?n+)?$,
39             and die("Invalid format");
40             },
41             coerce => sub {
42             defined( $_[0] )
43             or return [ 20, 10 ];
44             ref $_[0] eq "ARRAY" and return $_[0];
45              
46             my ( $fmta, $fmtb ) = ( $_[0] =~ m,^(\d?n+)(?:\^(\d?n+))?$, );
47             defined $fmtb or $fmtb = $fmta;
48             my $starta = "1";
49             my $startb = "1";
50             $fmta =~ s/^(\d)(.*)/$2/ and $starta = $1;
51             $fmtb =~ s/^(\d)(.*)/$2/ and $startb = $1;
52             my $maxa = $starta . "0" x length($fmta);
53             my $maxb = $startb . "0" x length($fmtb);
54             [ $maxa, $maxb ];
55             },
56             default => sub { [ 20, 10 ] },
57             format => "s",
58             short => "f",
59             );
60              
61             =head1 LICENSE AND COPYRIGHT
62              
63             Copyright 2010-2014 Jens Rehsack.
64              
65             This program is free software; you can redistribute it and/or modify it
66             under the terms of either: the GNU General Public License as published
67             by the Free Software Foundation; or the Artistic License.
68              
69             See http://dev.perl.org/licenses/ for more information.
70              
71             =cut
72              
73             1;