line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Modulino::Base; |
2
|
1
|
|
|
1
|
|
705
|
use utf8; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
3
|
1
|
|
|
1
|
|
23
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
16
|
|
4
|
1
|
|
|
1
|
|
5
|
no warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
9
|
use v5.10.1; |
|
1
|
|
|
|
|
2
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
3
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
378
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.002'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=encoding utf8 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Modulino::Base - Common stuff for the modulino demonstrations |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
0
|
|
|
sub _running_under_tester { !! $ENV{CPANTEST} } |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _running_as_app { |
25
|
0
|
|
|
0
|
|
|
my $caller = scalar caller(1); |
26
|
0
|
0
|
|
|
|
|
(defined $caller) && $caller ne 'main'; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# run directly |
30
|
|
|
|
|
|
|
if( ! defined caller(0) ) { |
31
|
|
|
|
|
|
|
carp sprintf "You cannot run %s directly!", __PACKAGE__; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
# loaded from a module that was run directly |
34
|
|
|
|
|
|
|
elsif( ! defined caller(1) ) { |
35
|
|
|
|
|
|
|
my @caller = caller(0); |
36
|
|
|
|
|
|
|
my $method = do { |
37
|
|
|
|
|
|
|
if( _running_under_tester() ) { 'test' } |
38
|
|
|
|
|
|
|
elsif( _running_as_app() ) { 'run' } |
39
|
|
|
|
|
|
|
else { undef } |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
if( $caller[0]->can( $method ) ) { |
43
|
|
|
|
|
|
|
$caller[0]->$method( @ARGV ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
elsif( __PACKAGE__->can( $method ) ) { # faking inheritance |
46
|
|
|
|
|
|
|
__PACKAGE__->$method( $caller[0], @ARGV ) |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
|
|
|
|
|
|
carp "There is no $method() method defined in $caller[0]\n"; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub test { |
54
|
0
|
|
|
0
|
0
|
|
my( $class, $caller ) = @_; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my @tests = do { |
57
|
0
|
0
|
|
|
|
|
if( $caller->can( '_get_tests' ) ) { |
58
|
0
|
|
|
|
|
|
$caller->_get_tests; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
else { |
61
|
0
|
|
|
|
|
|
$class->_get_tests( $caller ); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
}; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
require Test::More; |
66
|
0
|
|
|
|
|
|
Test::More::note( "Running $caller as a test" ); |
67
|
0
|
|
|
|
|
|
foreach my $test ( @tests ) { |
68
|
|
|
|
|
|
|
Test::More::subtest( $test => sub { |
69
|
0
|
|
|
0
|
|
|
my $rc = eval { $caller->$test(); 1 }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
Test::More::diag( $@ ) unless defined $rc; |
71
|
0
|
|
|
|
|
|
} ); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
Test::More::done_testing(); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _get_tests { |
78
|
0
|
|
|
0
|
|
|
my( $class, $caller ) = @_; |
79
|
0
|
|
|
|
|
|
print "_get_tests class is [$class]\n"; |
80
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
101
|
|
81
|
0
|
|
|
|
|
|
my $stub = $caller . '::'; |
82
|
|
|
|
|
|
|
my @tests = |
83
|
0
|
|
|
|
|
|
grep { defined &{"$stub$_"} } |
|
0
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
grep { 0 == index $_, '_test_' } |
85
|
0
|
|
|
|
|
|
keys %{ "$stub" }; |
|
0
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
@tests; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |