blib/lib/Templ.pm

filter: Statementstmt 94.1% 64 / 68 Branchbran 62.5% 15 / 24 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 92.8% 13 / 14 Podpod 0.0% 0 / 4 totaltotal 82.6% 95 / 115 CC 16 SCAR 13.9
CC
16
Cov
85%
import
6.5
__ANON__
6.2
templ_spec
5.1
CRAP 4.0
« Build ↑ Summary blib/lib/Templ/Tag/Filter.pm »
1 package Templ;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Scope::Upper qw(localize UP);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use File::Spec::Functions qw(catdir abs2rel curdir splitdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = "0.01_01";
12 1 $VERSION = eval $VERSION;
13  
14 1 our $spec_class;
15 BEGIN {
16 1 ▶ $Templ::spec_class = 'Templ::Spec::Basic';
Subroutine BEGIN: called CC=2 SCAR=7.0
17 # Somewhat inspired by Module::Find...
18 # Perform a "require MODULE;" for all Templ::* modules
19 1 foreach my $dir ( grep { -d } map { catdir($_,'Templ') } @INC ) {
20 my $wanted = sub {
21 51 ▶ return unless -r;
Subroutine __ANON__: called CC=6 SCAR=18.2
Branch: 1 branch
BranchTrueFalseTotal
unless -r $_ 0 51 51
22 51 ▶ return if abs2rel($_,$dir) !~ m/^(.*)\.pm$/;
Branch: 1 branch
BranchTrueFalseTotal
unless abs2rel($_, $dir) =~ /^(.*)\.pm$/ 12 39 51
23 39 my $module = join( '::', 'Templ', splitdir($1) );
24 39 ▶ return unless $module =~ m/^(\w+::)*\w+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $module =~ /^(\w+::)*\w+$/ 0 39 39
25 39 ▶ return if $Templ::loaded{$module}++;
Branch: 1 branch
BranchTrueFalseTotal
if $Templ::loaded{$module}++ 26 13 39
26 13 eval "require $module;";
27 13 ▶ $@ && croak $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and croak($@) 0 13 13
28 3 };
29 # Find the perl modules under thes dirs and "require" them
30 3 find( { wanted => $wanted, no_chdir => 1, follow => 1 }, $dir );
31 }
32 }
33  
34 1 ▶sub templ ($;$) { $spec_class->templ( @_ ) }
Subroutine templ: called CC=1 SCAR=0.0
Pod undocumented
35 1 ▶sub templ_method ($$;$) { $spec_class->templ_method( @_ ) }
Subroutine templ_method: called CC=1 SCAR=0.0
Pod undocumented
36 0 ▶sub templ_sub ($$;$) { $spec_class->templ_sub( @_ ) }
Subroutine templ_sub: not called CC=1 SCAR=6.9
Pod undocumented
37  
38 sub templ_spec (;$$) {
39 5 ▶ return $spec_class unless scalar @_;
Subroutine templ_spec: called CC=5 SCAR=16.3
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ 3 2 5
40 2 my $new_spec_class = shift;
41 2 ▶ my $context = shift || UP;
Condition66%2/3
shift() || &UP()
l!l&&r!l&&!r
101
MC/DC50%1/2
shift() || &UP()
shift() &UP()
Truth table66%2/3
A || B
A= shift()B= &UP()
ABresult
1X1
011
000
42 2 ▶ if ( not Templ::Spec::_subclass_loaded($new_spec_class) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&Templ::Spec::_subclass_loaded($new_spec_class)) 2 0 2
43 2 ▶ if ( $Templ::loaded{'Templ::Spec::'.$new_spec_class} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Templ::loaded{'Templ::Spec::' . $new_spec_class}) 2 0 2
44 2 $new_spec_class = 'Templ::Spec::'.$new_spec_class;
45 }
46 2 Templ::Spec::_load_subclass($new_spec_class);
47 }
48 2 localize '$Templ::spec_class', $new_spec_class, $context;
49 2 return $new_spec_class;
50 }
51  
52 sub import {
53 2 ▶ my $class = shift;
Subroutine import: called CC=6 SCAR=18.7
54 2 my %valid_exports = map { $_ => 1 } qw(templ templ_method templ_sub templ_spec);
55 2 my @export = ();
56 2 ▶ while (scalar @_) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 1 2 3
57 1 my $item = shift @_;
58 1 ▶ if ($item eq '-spec') {
Branch: 1 branch
BranchTrueFalseTotal
if ($item eq "-spec") 1 0 1
59 1 templ_spec( shift(@_), UP );
60 1 next;
61 }
62 0 ▶ if (not exists $valid_exports{$item}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $valid_exports{$item}) 0 0 0
63 0 croak "Unknown function: $item";
64 }
65 0 push @export, $item;
66 }
67 2 ▶ unless (scalar @export) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @export) 2 0 2
68 2 @export = keys %valid_exports;
69 }
70 2 foreach ( qw(templ templ_method templ_sub templ_spec) ) {
71 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
72 8 *{caller().'::'.$_} = \*{$_};
73 }
74 }
75  
76 1 1;
« Build ↑ Summary blib/lib/Templ/Tag/Filter.pm »