lib/Template/Plugin/List.pm

filter: Statementstmt 96.8% 61 / 63 Branchbran 100% 12 / 12 Conditioncond 81.8% 9 / 11 MC/DCmcdc 57.1% 4 / 7 Subroutinesub 94.4% 17 / 18 Podpod 7.6% 1 / 13 totaltotal 83.8% 104 / 124 CC 11 SCAR 14.7
CC
11
Cov
95%
new
10.0
item
2.0
throw
2.0
CRAP 4.3
« lib/Template/Base.pm ↑ Summary lib/Template/VMethods.pm »
1 #============================================================= -*-Perl-*-
2 #
3 # Template::Plugin::List
4 #
5 # DESCRIPTION
6 # Template Toolkit plugin to implement an OO List object.
7 # (work in progress)
8 #
9 # AUTHOR
10 # Andy Wardley <abw@wardley.org>
11 #
12 # COPYRIGHT
13 # Copyright (C) 2001-2022 Andy Wardley. All Rights Reserved.
14 #
15 # This module is free software; you can redistribute it and/or
16 # modify it under the same terms as Perl itself.
17 #
18 #============================================================================
19  
20 package Template::Plugin::List;
21  
22 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use base 'Template::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use Template::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 use overload
27 1 ▶ q|""| => "text",
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 fallback => 1;
29  
30 1 our $VERSION = '3.106';
31 1 our $ERROR = '';
32  
33  
34 1 local $" = ', ';
35  
36 #------------------------------------------------------------------------
37  
38 18 ▶sub new {
Subroutine new: called CC=10 SCAR=23.1
Pod documented
39 18 my ($class, @args) = @_;
40 18 ▶ my $context = ref $class ? undef : CORE::shift(@args);
Branch: 1 branch
BranchTrueFalseTotal
ref $class ? : 1 17 18
41 18 ▶ my $config = @args && ref $args[-1] eq 'HASH' ? CORE::pop(@args) : { };
Branch: 1 branch
BranchTrueFalseTotal
@args && ref $args[-1] eq 'HASH' ? : 3 15 18
Condition100%3/3
@args and ref $args[-1] eq "HASH"
!ll&&!rl&&r
1143
MC/DC100%2/2
@args and ref $args[-1] eq "HASH"
@args ref $args[-1] eq "HASH"
Truth table100%3/3
A and B
A= @argsB= ref $args[-1] eq "HASH"
ABresult
0X0
100
111
42  
43 18 ▶ $class = ref($class) || $class;
Condition66%2/3
ref $class || $class
l!l&&r!l&&!r
1170
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table66%2/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
44  
45 my $list = defined $config->{ list }
46 ? $config->{ list }
47 18 ▶ : (scalar @args == 1 && ref $args[0] eq 'ARRAY'
Branch: 2 branches
BranchTrueFalseTotal
defined $config->{'list'} ? : 1 17 18
scalar @args == 1 && ref $args[0] eq 'ARRAY' ? : 2 15 17
Condition66%2/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
1502
MC/DC50%1/2
scalar @args == 1 and ref $args[0] eq "ARRAY"
scalar @args == 1 ref $args[0] eq "ARRAY"
Truth table66%2/3
A and B
A= scalar @args == 1B= ref $args[0] eq "ARRAY"
ABresult
0X0
100
111
48 ? CORE::shift(@args)
49 : [ @args ]
50 );
51  
52 my $joint =
53 defined $config->{ joint }
54 ? $config->{ joint }
55 : $config->{ join }
56 ? $config->{ join }
57 18 ▶ : ', ';
Branch: 2 branches
BranchTrueFalseTotal
defined $config->{'joint'} ? : 1 17 18
$config->{'join'} ? : 1 16 17
58  
59 18 bless {
60 list => $list,
61 joint => $joint,
62 _CONTEXT => $context,
63 }, $class;
64 }
65  
66  
67 1 ▶sub list {
Subroutine list: called CC=1 SCAR=0.0
Pod undocumented
68 1 return $_[0]->{ list };
69 }
70  
71  
72 3 ▶sub item {
Subroutine item: called CC=2 SCAR=6.9
Pod undocumented
73 3 ▶ $_[0]->{ list }->[ $_[1] || 0 ];
Condition100%2/2
$_[1] || 0
l!l
21
MC/DC100%1/1
$_[1] || 0
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
74 }
75  
76  
77 1 ▶sub hash { ### not sure about this one ###
Subroutine hash: called CC=1 SCAR=0.0
Pod undocumented
78 1 my $self = shift;
79 1 my $n = 0;
80 1 return { map { ($n++, $_) } @{ $self->{ list } } };
81 }
82  
83  
84 11 ▶sub text {
Subroutine text: called CC=1 SCAR=0.0
Pod undocumented
85 11 my $self = CORE::shift;
86 11 return CORE::join($self->{ joint }, @{ $self->{ list } });
87 }
88  
89  
90 1 ▶sub copy {
Subroutine copy: called CC=1 SCAR=0.0
Pod undocumented
91 1 my $self = CORE::shift;
92 1 $self->new([ @{ $self->{ list } } ]);
93 }
94  
95  
96 0 ▶sub throw {
Subroutine throw: not called CC=1 SCAR=6.9
Pod undocumented
97 0 my $self = CORE::shift;
98 0 die (Template::Exception->new('List', CORE::join('', @_)));
99 }
100  
101  
102 #------------------------------------------------------------------------
103  
104 2 ▶sub push {
Subroutine push: called CC=1 SCAR=0.0
Pod undocumented
105 2 my $self = CORE::shift;
106 2 CORE::push(@{ $self->{ list } }, @_);
107 2 return $self;
108 }
109  
110  
111 1 ▶sub unshift {
Subroutine unshift: called CC=1 SCAR=0.0
Pod undocumented
112 1 my $self = CORE::shift;
113 1 CORE::unshift(@{ $self->{ list } }, @_);
114 1 return $self;
115 }
116  
117  
118 1 ▶sub pop {
Subroutine pop: called CC=1 SCAR=0.0
Pod undocumented
119 1 my $self = CORE::shift;
120 1 CORE::pop(@{ $self->{ list } });
121 1 return $self;
122 }
123  
124  
125 1 ▶sub shift {
Subroutine shift: called CC=1 SCAR=0.0
Pod undocumented
126 1 my $self = CORE::shift;
127 1 CORE::shift(@{ $self->{ list } });
128 1 return $self;
129 }
130  
131  
132 1 ▶sub max {
Subroutine max: called CC=1 SCAR=0.0
Pod undocumented
133 1 local $^W = 0;
134 1 my $list = $_[0]->{ list };
135 1 return $#$list;
136 }
137  
138  
139 5 ▶sub size {
Subroutine size: called CC=1 SCAR=0.0
Pod undocumented
140 5 local $^W = 0;
141 5 my $list = $_[0]->{ list };
142 5 return $#$list + 1;
143 }
144  
145  
146 1 1;
147  
148 __END__
« lib/Template/Base.pm ↑ Summary lib/Template/VMethods.pm »