SmokeBox.pm

filter: Statementstmt 85.2% 110 / 129 Branchbran 61.1% 22 / 36 Conditioncond 55.0% 11 / 20 MC/DCmcdc 25.0% 3 / 12 Subroutinesub 86.3% 19 / 22 Podpod 100% 9 / 9 totaltotal 76.3% 174 / 228 SCAR 38.6
CC
34
Cov
77%
_submit
17.5
_del_smoker
7.3
_start
6.2
CRAP 47.5
« SmokeBox/JobQueue.pm ↑ Summary SmokeBox/Smoker.pm »
1 package POE::Component::SmokeBox;
2 12 $POE::Component::SmokeBox::VERSION = '0.56';
3 #ABSTRACT: POE enabled CPAN smoke testing with added value.
4  
5 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use POE qw(Component::SmokeBox::Backend Component::SmokeBox::JobQueue);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use POE::Component::SmokeBox::Smoker;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use POE::Component::SmokeBox::Job;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use POE::Component::SmokeBox::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub spawn {
13 9 ▶ my $package = shift;
Subroutine spawn: called CC=4 SCAR=13.9
Pod documented
14 9 my %params = @_;
15 9 $params{lc $_} = delete $params{$_} for keys %params;
16 9 my $options = delete $params{'options'};
17 9 ▶ $params{'delay'} = 0 unless exists $params{'delay'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{"delay"} 7 2 9
18 9 my $self = bless \%params, $package;
19 9 ▶ $self->{session_id} = POE::Session->create(
Branch: 1 branch
BranchTrueFalseTotal
ref $options eq 'HASH' ? : 4 5 9
20 object_states => [
21 $self => {
22 shutdown => '_shutdown',
23 add_smoker => '_add_smoker',
24 del_smoker => '_del_smoker',
25 submit => '_submit',
26 register_ui => '_reg_ui',
27 unregister_ui => '_unreg_ui',
28 },
29 $self => [qw(_start)],
30 ],
31 heap => $self,
32 ( ref($options) eq 'HASH' ? ( options => $options ) : () ),
33 )->ID();
34 9 return $self;
35 }
36  
37 sub session_id {
38 45 ▶ return $_[0]->{session_id};
Subroutine session_id: called CC=1 SCAR=0.0
Pod documented
39 }
40  
41 sub multiplicity {
42 2 ▶ return $_[0]->{multiplicity};
Subroutine multiplicity: called CC=1 SCAR=0.0
Pod documented
43 }
44  
45 sub delay {
46 3 ▶ if ( defined $_[1] ) {
Subroutine delay: called CC=3 SCAR=18.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) { } 0 3 3
47 # verify it's an int
48 0 ▶ if ( $_[1] !~ /^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $_[1] =~ /^\d+$/) { } 0 0 0
49 0 return;
50 } else {
51 0 $_[0]->{delay} = $_[1];
52 0 return $_[1];
53 }
54 } else {
55 3 return $_[0]->{delay};
56 }
57 }
58  
59 sub queues {
60 20 ▶ return map { $_->{queue} } @{ $_[0]->{queues} };
Subroutine queues: called CC=1 SCAR=0.0
Pod documented
61 }
62  
63 sub shutdown {
64 9 ▶ my $self = shift;
Subroutine shutdown: called CC=1 SCAR=0.0
Pod documented
65 9 $poe_kernel->call( $self->session_id() => 'shutdown' => @_ );
66 }
67  
68 sub _start {
69 9 ▶ my ($kernel,$self) = @_[KERNEL,OBJECT];
Subroutine _start: called CC=6 SCAR=18.3
70 9 $self->{session_id} = $_[SESSION]->ID();
71 9 ▶ if ( $self->{alias} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'alias'}) { } 0 9 9
72 0 $kernel->alias_set( $self->{alias} );
73 }
74 else {
75 9 $kernel->refcount_increment( $self->{session_id} => __PACKAGE__ );
76 }
77 9 $self->{queues} = [ ];
78 9 my $smokers = delete $self->{smokers};
79 9 ▶ return unless $smokers and ref $smokers eq 'ARRAY' and scalar @{ $smokers };
Branch: 1 branch
BranchTrueFalseTotal
unless $smokers and ref $smokers eq "ARRAY" and scalar @{$smokers;} 0 6 6
Condition80%4/5
$smokers and ref $smokers eq "ARRAY" and scalar @{$smokers;}
!ll
36
$smokers and ref $smokers eq "ARRAY"
!ll&&!rl&&r
306
MC/DC50%1/2
$smokers and ref $smokers eq "ARRAY" and scalar @{$smokers;}
$smokers ref $smokers eq "ARRAY"
Truth table66%2/3
A and B
A= $smokersB= ref $smokers eq "ARRAY"
ABresult
0X0
100
111
80 6 $self->add_smoker( $_ ) for @{ $smokers };
81 6 return;
82 }
83  
84 sub _shutdown {
85 9 ▶ my ($kernel,$self) = @_[KERNEL,OBJECT];
Subroutine _shutdown: called CC=4 SCAR=14.3
86 9 ▶ if ( $self->{alias} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'alias'}) { } 0 9 9
87 0 $kernel->alias_remove($_) for $kernel->alias_list();
88 }
89 else {
90 9 $kernel->refcount_decrement( $self->{session_id} => __PACKAGE__ );
91 }
92 9 $_->{queue}->shutdown() for @{ $self->{queues} };
93 9 return;
94 }
95  
96 sub add_smoker {
97 31 ▶ my $self = shift;
Subroutine add_smoker: called CC=1 SCAR=0.0
Pod documented
98 31 $poe_kernel->call( $self->{session_id}, 'add_smoker', @_ );
99 }
100  
101 sub del_smoker {
102 11 ▶ my $self = shift;
Subroutine del_smoker: called CC=1 SCAR=0.0
Pod documented
103 11 $poe_kernel->call( $self->{session_id}, 'del_smoker', @_ );
104 }
105  
106 sub _add_smoker {
107 31 ▶ my ($kernel,$self,$state,$sender,$smoker) = @_[KERNEL,OBJECT,STATE,SENDER,ARG0];
Subroutine _add_smoker: called CC=5 SCAR=16.4
108 31 ▶ unless ( $smoker and $smoker->isa('POE::Component::SmokeBox::Smoker') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($smoker and $smoker->isa("POE::Component::SmokeBox::Smoker")) 0 31 31
Condition33%1/3
$smoker and $smoker->isa("POE::Component::SmokeBox::Smoker")
!ll&&!rl&&r
0031
MC/DC0%0/2
$smoker and $smoker->isa("POE::Component::SmokeBox::Smoker")
$smoker $smoker->isa("POE::Component::SmokeBox::Smoker")
Truth table33%1/3
A and B
A= $smokerB= $smoker->isa("POE::Component::SmokeBox::Smoker")
ABresult
0X0
100
111
109 0 warn "ARG0 must be a 'POE::Component::SmokeBox::Smoker' object\n";
110 0 return;
111 }
112 # If no jobqueues start a job queue.
113 # If multiplicity start a job queue for each smoker object.
114 31 ▶ if ( $self->{multiplicity} or scalar @{ $self->{queues} } == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"multiplicity"} or scalar @{$self->{"queues"};} == 0) 17 14 31
Condition100%3/3
$self->{"multiplicity"} or scalar @{$self->{"queues"};} == 0
l!l&&r!l&&!r
10714
MC/DC100%2/2
$self->{"multiplicity"} or scalar @{$self->{"queues"};} == 0
$self->{"multiplicity"} scalar @{$self->{"queues"};} == 0
Truth table100%3/3
A or B
A= $self->{"multiplicity"}B= scalar @{$self->{"queues"};} == 0
ABresult
1X1
011
000
115 17 my $queue = { };
116 $queue->{queue} = POE::Component::SmokeBox::JobQueue->spawn(
117 'delay' => $self->{delay},
118 17 );
119 17 push @{ $queue->{smokers} }, $smoker;
120 17 push @{ $self->{queues} }, $queue;
121 17 return;
122 }
123 # Otherwise we just add the smoker to our existing queue
124 14 push @{ $self->{queues}->[0]->{smokers} }, $smoker;
125 14 return;
126 }
127  
128 sub _del_smoker {
129 11 ▶ my ($kernel,$self,$state,$sender,$smoker) = @_[KERNEL,OBJECT,STATE,SENDER,ARG0];
Subroutine _del_smoker: called CC=7 SCAR=19.8
130 11 ▶ unless ( $smoker and $smoker->isa('POE::Component::SmokeBox::Smoker') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($smoker and $smoker->isa("POE::Component::SmokeBox::Smoker")) 0 11 11
Condition33%1/3
$smoker and $smoker->isa("POE::Component::SmokeBox::Smoker")
!ll&&!rl&&r
0011
MC/DC0%0/2
$smoker and $smoker->isa("POE::Component::SmokeBox::Smoker")
$smoker $smoker->isa("POE::Component::SmokeBox::Smoker")
Truth table33%1/3
A and B
A= $smokerB= $smoker->isa("POE::Component::SmokeBox::Smoker")
ABresult
0X0
100
111
131 0 warn "ARG0 must be a 'POE::Component::SmokeBox::Smoker' object\n";
132 0 return;
133 }
134 11 my $x = 0;
135 11 foreach my $queue ( @{ $self->{queues} } ) {
136 17 my $i = 0;
137 17 for ( @{ $queue->{smokers} } ) {
138 29 ▶ splice(@{ $queue->{smokers} }, $i, 1) if $_ == $smoker;
Branch: 1 branch
BranchTrueFalseTotal
if $_ == $smoker 8 21 29
139 29 ++$i;
140 }
141 17 ▶ unless ( scalar @{ $queue->{smokers} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @{$queue->{"smokers"};}) 3 14 17
142 3 splice(@{ $self->{queues} }, $x, 1);
143 3 $queue->{queue}->shutdown();
144 }
145 17 ++$x;
146 }
147 11 return;
148 }
149  
150 sub submit {
151 0 ▶ my $self = shift;
Subroutine submit: not called CC=1 SCAR=6.9
Pod documented
152 0 $poe_kernel->call( $self->{session_id}, 'submit', @_ );
153 }
154  
155 sub _submit {
156 36 ▶ my ($kernel,$self,$state,$sender) = @_[KERNEL,OBJECT,STATE,SENDER];
Subroutine _submit: called CC=11 SCAR=28.6
157 36 ▶ return if $self->{_shutdown};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_shutdown"} 0 36 36
158 36 my $args;
159 36 ▶ if ( ref( $_[ARG0] ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[10] eq 'HASH') { } 0 36 36
160 0 $args = { %{ $_[ARG0] } };
161 }
162 else {
163 36 $args = { @_[ARG0..$#_] };
164 }
165  
166 36 $args->{lc $_} = delete $args->{$_} for grep { $_ !~ /^_/ } keys %{ $args };
167  
168 36 ▶ unless ( $args->{event} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"event"}) 0 36 36
169 0 warn "No 'event' specified for $state\n";
170 0 return;
171 }
172  
173 36 ▶ unless ( $args->{job} and $args->{job}->isa('POE::Component::SmokeBox::Job') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"job"} and $args->{"job"}->isa("POE::Component::SmokeBox::Job")) 0 36 36
Condition33%1/3
$args->{"job"} and $args->{"job"}->isa("POE::Component::SmokeBox::Job")
!ll&&!rl&&r
0036
MC/DC0%0/2
$args->{"job"} and $args->{"job"}->isa("POE::Component::SmokeBox::Job")
$args->{"job"} $args->{"job"}->isa("POE::Component::SmokeBox::Job")
Truth table33%1/3
A and B
A= $args->{"job"}B= $args->{"job"}->isa("POE::Component::SmokeBox::Job")
ABresult
0X0
100
111
174 0 warn "No 'job' specified for $state or it was not a valid 'POE::Component::SmokeBox::Job' object\n";
175 0 return;
176 }
177  
178 36 ▶ if ( $args->{session} and my $ref = $kernel->alias_resolve( $args->{session} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'session'} and my $ref = $kernel->alias_resolve($args->{'session'})) { } 0 36 36
Condition33%1/3
$args->{"session"} and my $ref = $kernel->alias_resolve($args->{"session"})
!ll&&!rl&&r
3600
MC/DC0%0/2
$args->{"session"} and my $ref = $kernel->alias_resolve($args->{"session"})
$args->{"session"} my $ref = $kernel->alias_resolve($args->{"session"})
Truth table33%1/3
A and B
A= $args->{"session"}B= my $ref = $kernel->alias_resolve($args->{"session"})
ABresult
0X0
100
111
179 0 $args->{session} = $ref->ID();
180 }
181 else {
182 36 $args->{session} = $sender->ID();
183 }
184  
185 36 ▶ warn "No smokers have been defined yet!!!!!\n" unless scalar @{ $self->{queues} };
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$self->{"queues"};} 0 36 36
186  
187 36 foreach my $q ( @{ $self->{queues} } ) {
188 44 $args->{smokers} = [ @{ $q->{smokers} } ];
189 44 $q->{queue}->submit( $args );
190 }
191  
192 36 return;
193 }
194  
195 ▶sub _reg_ui {
Subroutine _reg_ui: not called CC=1 SCAR=0.0
196 }
197  
198 ▶sub _unreg_ui {
Subroutine _unreg_ui: not called CC=1 SCAR=0.0
199 }
200  
201 12 "We've Got a Fuzzbox and We're Gonna Use It";
202  
203 __END__
« SmokeBox/JobQueue.pm ↑ Summary SmokeBox/Smoker.pm »