Filter.pm

filter: Statementstmt 96.9% 64 / 66 Branchbran 66.6% 4 / 6 Conditioncond 85.7% 6 / 7 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 1 totaltotal 92.7% 90 / 97 CC 9 SCAR 10.1
CC
9
Cov
94%
setup
6.2
_target_can
2.0
_target_AUTOLOAD
2.0
CRAP 2.8
« LocaleObject.pm ↑ Summary en_PIGLATIN.pm »
1 # Copyright 2009, 2010, 2011, 2013, 2016 Kevin Ryde
2  
3 # This file is part of Time-Duration-Locale.
4 #
5 # Time-Duration-Locale is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as published
7 # by the Free Software Foundation; either version 3, or (at your option) any
8 # later version.
9 #
10 # Time-Duration-Locale is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 # Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Time-Duration-Locale. If not, see <http://www.gnu.org/licenses/>.
17  
18 package Time::Duration::Filter;
19 2 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use Module::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use vars qw($VERSION $AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 2 $VERSION = 12;
27  
28 # uncomment this to run the ### lines
29 # use Smart::Comments;
30  
31  
32 2 my @_target_ISA = ('Exporter');
33  
34 2 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
35 2 shift; # $class own __PACKAGE__
36 2 setup (scalar caller(), @_);
37 }
38 2 ▶sub setup {
Subroutine setup: called CC=6 SCAR=18.2
Pod undocumented
39 2 my ($package, %options) = @_;
40 2 ▶ my $from = $options{'from'} || 'Time::Duration';
Condition50%1/2
$options{'from'} || 'Time::Duration'
l!l
02
MC/DC0%0/1
$options{'from'} || 'Time::Duration'
$options{'from'}
Truth table50%1/2
A
A= $options{'from'}
Aresult
11
00
41 2 Module::Load::load ($from);
42  
43 ### setup: $package
44 ### $from
45 2 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 2 *{"${package}::AUTOLOAD"} = \&_target_AUTOLOAD;
47 2 *{"${package}::can"} = \&_target_can;
48 2 ${"${package}::_from"} = $from;
49  
50 2 require Exporter;
51 2 *{"${package}::ISA"} = \@_target_ISA;
52  
53 # same exports as the $from package
54 2 foreach my $varname ('EXPORT','EXPORT_OK') {
55 4 ▶ if (my $aref = *{"${from}::$varname"}{ARRAY}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $aref = *{"${from}::$varname";}{"ARRAY"}) 4 0 4
56 ### store array: $varname
57 4 *{"${package}::$varname"} = $aref;
58 }
59 }
60 2 foreach my $varname ('EXPORT_TAGS') {
61 2 ▶ if (my $href = *{"${from}::$varname"}{HASH}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $href = *{"${from}::$varname";}{"HASH"}) 0 2 2
62 ### store hash: $varname
63 0 *{"${package}::$varname"} = $href;
64 }
65 }
66 }
67  
68 3 ▶sub _target_can {
Subroutine _target_can: called CC=2 SCAR=6.9
69 3 my ($class, $name) = @_;
70 3 ▶ return ($class->SUPER::can($name) || _make_func ($class, $name));
Condition100%3/3
$class->SUPER::can($name) || _make_func($class, $name)
l!l&&r!l&&!r
111
MC/DC100%2/2
$class->SUPER::can($name) || _make_func($class, $name)
$class->SUPER::can($name) _make_func($class, $name)
Truth table100%3/3
A || B
A= $class->SUPER::can($name)B= _make_func($class, $name)
ABresult
1X1
011
000
71 }
72 13 ▶sub _target_AUTOLOAD {
Subroutine _target_AUTOLOAD: called CC=2 SCAR=6.9
73 ### TDF AUTOLOAD of: $AUTOLOAD
74 13 my ($package, $name) = ($AUTOLOAD =~ /(.*)::(.*)/);
75 my $subr = _make_func ($package, $name)
76 13 ▶ || die "No function $name exported by " . ${"${package}::_from"};
Condition100%2/2
_make_func($package, $name) || die("No function $name exported by " . ${"${package}::_from";})
l!l
121
MC/DC100%1/1
_make_func($package, $name) || die("No function $name exported by " . ${"${package}::_from";})
_make_func($package, $name)
Truth table100%2/2
A
A= _make_func($package, $name)
Aresult
11
00
77 12 goto $subr;
78 }
79  
80 15 ▶sub _make_func {
Subroutine _make_func: called CC=2 SCAR=6.9
81 15 my ($package, $name) = @_;
82  
83 15 ▶ scalar(grep {$_ eq $name} @{"${package}::EXPORT_OK"})
Branch: 1 branch
BranchTrueFalseTotal
scalar grep({$_ eq $name;} @{"${package}::EXPORT_OK";}) or return 13 2 15
84 or return; # no such function
85  
86 13 my $from = ${"${package}::_from"};
87 13 my $from_func = "${from}::$name";
88 13 my $filter_func = "${package}::_filter";
89 ### from: $from_func
90 ### filter: $filter_func
91  
92 13 ▶ my $subr = sub { &$filter_func (&$from_func (@_)) };
Subroutine __ANON__: called CC=1 SCAR=0.0
93 13 *{"${package}::$name"} = $subr;
94 13 return $subr;
95 }
96  
97  
98 # if ($name eq '_filter') {
99 # die "$package didn't define a _filter() function";
100 # }
101 # if ($name =~ /^_f/) {
102 # die "Oops, bad autoload $AUTOLOAD";
103 # }
104  
105 2 1;
106 __END__
« LocaleObject.pm ↑ Summary en_PIGLATIN.pm »