GX/Callback/Hook/Queue.pm

filter: Statementstmt 88.2% 98 / 111 Branchbran 80.9% 34 / 42 Conditioncond 80.0% 12 / 15 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 88.8% 16 / 18 Podpod 100% 12 / 12 totaltotal 85.4% 176 / 206 CC 33 SCAR 20.3
CC
33
Cov
86%
skip_to
16.3
add
6.2
remove
6.1
CRAP 7.6
« GX/HTTP/Body/File.pm ↑ Summary GX/HTTP/Body/Scalar.pm »
1 # ----------------------------------------------------------------------------------------------------------------------
2 # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de>
3 # File: GX/Callback/Hook/Queue.pm
4 # ----------------------------------------------------------------------------------------------------------------------
5  
6 package GX::Callback::Hook::Queue;
7  
8 41 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 41 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 41 ▶use GX::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 41 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 # ----------------------------------------------------------------------------------------------------------------------
17 # Constructor
18 # ----------------------------------------------------------------------------------------------------------------------
19  
20 19 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
21  
22 19 my $class = shift;
23  
24 19 my $self = bless [ [ undef ] ], $class;
25  
26 19 return $self;
27  
28 }
29  
30  
31 # ----------------------------------------------------------------------------------------------------------------------
32 # Public methods
33 # ----------------------------------------------------------------------------------------------------------------------
34  
35 32 ▶sub add {
Subroutine add: called CC=6 SCAR=18.3
Pod documented
36  
37 32 my $self = shift;
38  
39 32 for ( @_ ) {
40  
41 55 ▶ if ( ! blessed $_ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($_)) 0 55 55
42 0 complain "Invalid argument";
43 }
44  
45 55 ▶ if ( $_->isa( 'GX::Callback' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_->isa('GX::Callback')) { } 7 48 55
elsif ($_->isa('GX::Callback::Hook')) { } 48 0 48
46 7 my $callback = $_;
47 7 push @$self, [ $callback ];
48 }
49 elsif ( $_->isa( 'GX::Callback::Hook' ) ) {
50 48 my $hook = $_;
51 48 my $hook_name = $hook->name;
52 48 my @callbacks = $hook->all;
53 48 ▶ push @$self, map { [ $_, $hook, $hook_name ] } ( @callbacks ? @callbacks : ( undef ) );
Branch: 1 branch
BranchTrueFalseTotal
@callbacks ? : 40 8 48
54 }
55 else {
56 0 complain "Invalid argument";
57 }
58  
59 };
60  
61 32 return;
62  
63 }
64  
65 0 ▶sub clear {
Subroutine clear: not called CC=1 SCAR=6.9
Pod documented
66  
67 0 my $self = shift;
68  
69 0 @$self = ( [ undef ] );
70  
71 0 return;
72  
73 }
74  
75 0 ▶sub clone {
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
76  
77 0 my $self = shift;
78  
79 0 return bless [ @$self ], ref $self;
80  
81 }
82  
83 48 ▶sub current {
Subroutine current: called CC=2 SCAR=7.6
Pod documented
84  
85 48 ▶ return ( $_[0]->[0] || return )->[0];
Condition50%1/2
$_[0][0] || (return)
l!l
480
MC/DC0%0/1
$_[0][0] || (return)
$_[0][0]
Truth table50%1/2
A
A= $_[0][0]
Aresult
11
00
86  
87 }
88  
89 36 ▶sub current_hook {
Subroutine current_hook: called CC=2 SCAR=7.6
Pod documented
90  
91 36 ▶ return ( $_[0]->[0] || return )->[1];
Condition50%1/2
$_[0][0] || (return)
l!l
360
MC/DC0%0/1
$_[0][0] || (return)
$_[0][0]
Truth table50%1/2
A
A= $_[0][0]
Aresult
11
00
92  
93 }
94  
95 38 ▶sub next {
Subroutine next: called CC=4 SCAR=13.9
Pod documented
96  
97 38 my $self = shift;
98  
99 38 my $current = shift @$self;
100  
101 38 ▶ while ( @$self ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$self) 37 9 46
102 37 ▶ return $self->[0][0] || shift( @$self ) && next;
Condition80%4/5
$self->[0][0] || shift @$self && (next)
l!l&&r!l&&!r
2971
shift @$self and next
!ll
08
MC/DC0%0/2
$self->[0][0] || shift @$self && (next)
$self->[0][0] shift @$self
Truth table66%2/3
A || B
A= $self->[0][0]B= shift @$self
ABresult
1X1
011
000
103 }
104  
105 9 @$self = ( $current );
106  
107 9 return;
108  
109 }
110  
111 35 ▶sub all {
Subroutine all: called CC=2 SCAR=6.9
Pod documented
112  
113 35 my $self = shift;
114  
115 35 ▶ if ( @$self > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$self > 1) { } 29 6 35
116 29 return grep { defined } map { $_->[0] } @$self[ 1 .. $#$self ];
117 }
118 else {
119 6 return;
120 }
121  
122 }
123  
124 20 ▶sub remove {
Subroutine remove: called CC=6 SCAR=18.1
Pod documented
125  
126 20 my $self = shift;
127  
128 20 my $count = @$self;
129  
130 20 for ( @_ ) {
131  
132 20 ▶ if ( ! defined $_ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_) 0 20 20
133 0 complain "Invalid argument";
134 }
135  
136 20 ▶ if ( blessed $_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($_)) { } 14 6 20
137  
138 14 ▶ if ( $_->isa( 'GX::Callback' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_->isa('GX::Callback')) { } 7 7 14
elsif ($_->isa('GX::Callback::Hook')) { } 7 0 7
139 7 my $callback = $_;
140 7 @$self = ( shift( @$self ), grep( { $_->[0] != $callback } @$self ) );
141 }
142 elsif ( $_->isa( 'GX::Callback::Hook' ) ) {
143 7 my $hook = $_;
144 7 @$self = ( shift( @$self ), grep( { $_->[1] != $hook } @$self ) );
145 }
146 else {
147 0 complain "Invalid argument";
148 }
149  
150 }
151 else {
152 6 my $hook_name = $_;
153 41 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
154 6 @$self = ( shift( @$self ), grep( { $_->[2] ne $hook_name } @$self ) );
155 }
156  
157 }
158  
159 20 return $count - @$self;
160  
161 }
162  
163 4 ▶sub remove_all {
Subroutine remove_all: called CC=1 SCAR=0.0
Pod documented
164  
165 4 my $self = shift;
166  
167 4 @$self = ( $self->[0] );
168  
169 4 return;
170  
171 }
172  
173 2 ▶sub replace_all {
Subroutine replace_all: called CC=2 SCAR=7.1
Pod documented
174  
175 2 my $self = shift;
176  
177 2 $self->remove_all;
178  
179 2 eval {
180 2 $self->add( @_ );
181 };
182  
183 2 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
184 0 complain $@;
185 }
186  
187 2 return;
188  
189 }
190  
191 32 ▶sub skip_to {
Subroutine skip_to: called CC=16 SCAR=27.9
Pod documented
192  
193 32 my $self = shift;
194  
195 32 ▶ if ( @_ != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ != 1) 0 32 32
196 0 complain "Invalid number of arguments";
197 }
198  
199 32 my $position;
200  
201 32 ▶ if ( blessed $_[0] ) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($_[0])) { } 25 7 32
elsif (defined $_[0]) { } 7 0 7
202  
203 25 ▶ if ( $_[0]->isa( 'GX::Callback' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_[0]->isa('GX::Callback')) { } 12 13 25
elsif ($_[0]->isa('GX::Callback::Hook')) { } 13 0 13
204  
205 12 my $callback = $_[0];
206  
207 12 my $i = 0;
208  
209 12 for ( @$self ) {
210 29 ▶ $position = $i, last if defined( $_->[0] ) && $_->[0] == $callback;
Branch: 1 branch
BranchTrueFalseTotal
if defined $_->[0] and $_->[0] == $callback 12 17 29
Condition100%3/3
defined $_->[0] and $_->[0] == $callback
!ll&&!rl&&r
12512
MC/DC100%2/2
defined $_->[0] and $_->[0] == $callback
defined $_->[0] $_->[0] == $callback
Truth table100%3/3
A and B
A= defined $_->[0]B= $_->[0] == $callback
ABresult
0X0
100
111
211 17 $i++;
212 }
213  
214 }
215 elsif ( $_[0]->isa( 'GX::Callback::Hook' ) ) {
216  
217 13 my $hook = $_[0];
218  
219 13 my $i = 0;
220  
221 13 for ( @$self ) {
222 37 ▶ $position = $i, last if defined( $_->[1] ) && $_->[1] == $hook;
Branch: 1 branch
BranchTrueFalseTotal
if defined $_->[1] and $_->[1] == $hook 11 26 37
Condition100%3/3
defined $_->[1] and $_->[1] == $hook
!ll&&!rl&&r
81811
MC/DC100%2/2
defined $_->[1] and $_->[1] == $hook
defined $_->[1] $_->[1] == $hook
Truth table100%3/3
A and B
A= defined $_->[1]B= $_->[1] == $hook
ABresult
0X0
100
111
223 26 $i++;
224 }
225  
226 }
227 else {
228 0 complain "Invalid argument";
229 }
230  
231 }
232 elsif ( defined $_[0] ) {
233  
234 7 my $hook_name = $_[0];
235  
236 7 my $i = 0;
237  
238 7 for ( @$self ) {
239 41 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
240 25 ▶ $position = $i, last if $_->[2] eq $hook_name;
Branch: 1 branch
BranchTrueFalseTotal
if $_->[2] eq $hook_name 3 22 25
241 22 $i++;
242 }
243  
244 }
245 else {
246 0 complain "Invalid argument";
247 }
248  
249 32 ▶ if ( $position ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($position) 25 7 32
250  
251 25 ▶ if ( $position > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($position > 1) 12 13 25
252 12 splice( @$self, 1, $position - 1 );
253 }
254  
255 25 return 1;
256  
257 }
258  
259 7 return;
260  
261 }
262  
263  
264 41 1;
265  
266 __END__
« GX/HTTP/Body/File.pm ↑ Summary GX/HTTP/Body/Scalar.pm »