Sandbox/Library.pm

filter: Statementstmt 100% 58 / 58 Branchbran 100% 22 / 22 Conditioncond 36.3% 4 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 87.2% 96 / 110 CC 21 SCAR 23.8
CC
21
Cov
92%
export_template_functions
17.0
set_library_functions
3.2
set_library_tags
2.1
CRAP 10.8
« Sandbox.pm ↑ Summary Sandbox/NumberFunctions.pm »
1 package Template::Sandbox::Library;
2 # ABSTRACT: Base library object for Template::Sandbox functions.
3  
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 ▶use Template::Sandbox;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 my %function_library = ();
12 6 my %function_tags = ();
13  
14 BEGIN
15 6 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 $Template::Sandbox::Library::VERSION = '1.04_01';
17 }
18  
19 sub import
20 13 ▶{
Subroutine import: called CC=2 SCAR=6.9
21 13 my $pkg = shift;
22  
23 13 ▶ export_template_functions( $pkg, 'Template::Sandbox', @_ ) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 8 5 13
24 }
25  
26 sub export_template_functions
27 26 ▶{
Subroutine export_template_functions: called CC=17 SCAR=28.3
Pod documented
28 26 my ( $this, $template, @imports ) = @_;
29 26 my ( $pkg, $library, $tags, %export, @functions, $existing );
30  
31 26 ▶ $pkg = ref( $this ) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0260
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
32  
33 croak "\"$pkg\" does not appear to be a template function library."
34 26 ▶ unless $function_library{ $pkg };
Branch: 1 branch
BranchTrueFalseTotal
unless $function_library{$pkg} 1 25 26
35  
36 25 $library = $function_library{ $pkg };
37 25 $tags = $function_tags{ $pkg };
38  
39 25 %export = ();
40 25 foreach my $import ( @imports )
41 {
42 34 foreach my $word ( split( /\s+/, $import ) )
43 {
44 34 my ( $delete );
45  
46 34 ▶ $delete = 1 if $word =~ s/^!//;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/^!// 6 28 34
47  
48 34 ▶ if( $word =~ s/^:// )
Branch: 1 branch
BranchTrueFalseTotal
if ($word =~ s/^://) { } 17 17 34
49 {
50 17 my ( @names );
51  
52 17 ▶ if( exists $tags->{ $word } )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $tags->{$word}) { } 7 10 17
elsif ($word eq 'all') { } 9 1 10
53 {
54 7 @names = @{$tags->{ $word }};
55 }
56 elsif( $word eq 'all' )
57 {
58 9 @names = keys( %{$library} );
59 }
60 else
61 {
62 1 croak "\"$word\" is not a template library tag in $pkg";
63 }
64  
65 16 ▶ if( $delete )
Branch: 1 branch
BranchTrueFalseTotal
if ($delete) { } 3 13 16
66 {
67 3 delete $export{ $_ } foreach ( @names );
68 }
69 else
70 {
71 13 $export{ $_ } = 1 foreach ( @names );
72 }
73 }
74 else
75 {
76 17 ▶ if( $delete )
Branch: 1 branch
BranchTrueFalseTotal
if ($delete) { } 3 14 17
77 {
78 3 delete $export{ $word };
79 }
80 else
81 {
82 14 $export{ $word } = 1;
83 }
84 }
85 }
86 }
87  
88 24 $existing = $template->_find_local_functions();
89  
90 24 @functions = ();
91 24 foreach my $name ( keys( %export ) )
92 {
93 croak "\"$name\" is not a template library function in $pkg"
94 55 ▶ unless $library->{ $name };
Branch: 1 branch
BranchTrueFalseTotal
unless $library->{$name} 1 54 55
95  
96 push @functions, $name => $library->{ $name }
97 54 ▶ unless exists $existing->{ $name };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $existing->{$name} 53 1 54
98 }
99  
100 23 ▶ $template->register_template_function( @functions ) if @functions;
Branch: 1 branch
BranchTrueFalseTotal
if @functions 21 2 23
101 }
102  
103 sub set_library_functions
104 8 ▶{
Subroutine set_library_functions: called CC=3 SCAR=11.8
Pod documented
105 8 my ( $this, %functions ) = @_;
106 8 my ( $pkg );
107  
108 8 ▶ $pkg = ref( $this ) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
080
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
109  
110 8 $function_library{ $pkg } = \%functions;
111 8 ▶ $function_tags{ $pkg } ||= {};
Condition50%1/2
$function_tags{$pkg} ||= {}
l!l
08
MC/DC0%0/1
$function_tags{$pkg} ||= {}
$function_tags{$pkg}
Truth table50%1/2
A
A= $function_tags{$pkg}
Aresult
11
00
112 }
113  
114 sub set_library_tags
115 4 ▶{
Subroutine set_library_tags: called CC=2 SCAR=7.4
Pod documented
116 4 my ( $this, %tags ) = @_;
117 4 my ( $pkg );
118  
119 4 ▶ $pkg = ref( $this ) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
120  
121 4 $function_tags{ $pkg } = \%tags;
122 }
123  
124 6 1;
125  
126 __END__
« Sandbox.pm ↑ Summary Sandbox/NumberFunctions.pm »