Benchmarker/GetInstalledLoops.pm

filter: Statementstmt 51.0% 48 / 94 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 62.5% 15 / 24 Podpod 0.0% 0 / 7 totaltotal 44.6% 63 / 141 CC 9 SCAR 19.3
CC
9
Cov
44%
find_loops
30.0
_start
6.0
_stop
6.0
CRAP 6.9
« Benchmarker/SubProcess.pm ↑ Summary Benchmarker/Imager/BasicStatistics.pm »
1 # Declare our package
2 package POE::Devel::Benchmarker::GetInstalledLoops;
3 1 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # Initialize our version
6 1 ▶use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 $VERSION = '0.05';
8  
9 # auto-export the only sub we have
10 1 ▶use base qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 our @EXPORT = qw( getPOEloops );
12  
13 # Import what we need from the POE namespace
14 1 ▶use POE qw( Session Filter::Line Wheel::Run );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use base 'POE::Session::AttributeBased';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # Get the utils
18 1 ▶use POE::Devel::Benchmarker::Utils qw ( knownloops );
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # analyzes the installed perl directory for available loops
21 0 ▶sub getPOEloops {
Subroutine getPOEloops: not called CC=1 SCAR=6.9
Pod undocumented
22 0 my $quiet_mode = shift;
23 0 my $forceloops = shift;
24  
25 # create our session!
26 0 POE::Session->create(
27 POE::Devel::Benchmarker::GetInstalledLoops->inline_states(),
28 'heap' => {
29 'quiet_mode' => $quiet_mode,
30 'loops' => $forceloops,
31 },
32 );
33 }
34  
35 # Starts up our session
36 0 ▶sub _start : State {
Subroutine _start: not called CC=2 SCAR=17.9
37 # set our alias
38 0 $_[KERNEL]->alias_set( 'Benchmarker::GetInstalledLoops' );
39  
40 # load our known list of loops
41 # known impossible loops:
42 # XS::EPoll ( must be POE > 1.003 and weird way of loading )
43 # XS::Poll ( must be POE > 1.003 and weird way of loading )
44 0 ▶ if ( ! defined $_[HEAP]->{'loops'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[3]{"loops"}) 0 0 0
45 0 $_[HEAP]->{'loops'} = knownloops();
46 }
47  
48 # First of all, we need to find out what loop libraries are installed
49 0 $_[HEAP]->{'found_loops'} = [];
50 0 $_[KERNEL]->yield( 'find_loops' );
51  
52 0 return;
53 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 0 ▶sub _stop : State {
Subroutine _stop: not called CC=2 SCAR=17.9
56 # tell the wheel to kill itself
57 0 ▶ if ( defined $_[HEAP]->{'WHEEL'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[3]{"WHEEL"}) 0 0 0
58 0 $_[HEAP]->{'WHEEL'}->kill( 9 );
59 0 undef $_[HEAP]->{'WHEEL'};
60 }
61  
62 0 return;
63 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 # loops over the "known" loops and sees if they are installed
66 0 ▶sub find_loops : State {
Subroutine find_loops: not called CC=5 SCAR=34.0
Pod undocumented
67 # get the loop to test
68 0 $_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
69  
70 # do we have something to test?
71 0 ▶ if ( ! defined $_[HEAP]->{'current_loop'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $_[3]{'current_loop'}) { } 0 0 0
72 # we're done!
73 0 $_[KERNEL]->alias_remove( 'Benchmarker::GetInstalledLoops' );
74 0 $_[KERNEL]->post( 'Benchmarker', 'found_loops', $_[HEAP]->{'found_loops'} );
75 0 return;
76 } else {
77 0 ▶ if ( ! $_[HEAP]->{'quiet_mode'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_[3]{"quiet_mode"}) 0 0 0
78 0 print "[LOOPSEARCH] Trying to find if POE::Loop::" . $_[HEAP]->{'current_loop'} . " is installed...\n";
79 }
80  
81 # set the flag
82 0 $_[HEAP]->{'test_failure'} = 0;
83 }
84  
85 # Okay, create the wheel::run to handle this
86 $_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
87 'Program' => $^X,
88 'ProgramArgs' => [ '-MPOE',
89 0 '-MPOE::Loop::' . $_[HEAP]->{'current_loop'},
90 '-e',
91 '1',
92 ],
93  
94 # Kill off existing FD's
95 'CloseOnCall' => 1,
96  
97 # setup our data handlers
98 'StdoutEvent' => 'Got_STDOUT',
99 'StderrEvent' => 'Got_STDERR',
100  
101 # the error handler
102 'ErrorEvent' => 'Got_ERROR',
103 'CloseEvent' => 'Got_CLOSED',
104  
105 # set our filters
106 'StderrFilter' => POE::Filter::Line->new(),
107 'StdoutFilter' => POE::Filter::Line->new(),
108 );
109 0 ▶ if ( ! defined $_[HEAP]->{'WHEEL'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $_[3]{'WHEEL'}) { } 0 0 0
110 0 die '[LOOPSEARCH] Unable to create a new wheel!';
111 } else {
112 # smart CHLD handling
113 0 ▶ if ( $_[KERNEL]->can( "sig_child" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[2]->can('sig_child')) { } 0 0 0
114 0 $_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
115 } else {
116 0 $_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
117 }
118 }
119 0 return;
120 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
121  
122 # Got a CHLD event!
123 0 ▶sub Got_CHLD : State {
Subroutine Got_CHLD: not called CC=1 SCAR=6.9
Pod undocumented
124 0 $_[KERNEL]->sig_handled();
125 0 return;
126 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
127  
128 # Handles child STDERR output
129 0 ▶sub Got_STDERR : State {
Subroutine Got_STDERR: not called CC=1 SCAR=6.9
Pod undocumented
130 0 my $input = $_[ARG0];
131  
132 # since we got an error, must be a failure
133 0 $_[HEAP]->{'test_failure'} = 1;
134  
135 0 return;
136 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
137  
138 # Handles child STDOUT output
139 0 ▶sub Got_STDOUT : State {
Subroutine Got_STDOUT: not called CC=1 SCAR=6.9
Pod undocumented
140 0 my $input = $_[ARG0];
141  
142 0 return;
143 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
144  
145 # Handles child error
146 0 ▶sub Got_ERROR : State {
Subroutine Got_ERROR: not called CC=2 SCAR=17.9
Pod undocumented
147 # Copied from POE::Wheel::Run manpage
148 0 my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
149  
150 # ignore exit 0 errors
151 0 ▶ if ( $errnum != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($errnum != 0) 0 0 0
152 0 warn "Wheel::Run got an $operation error $errnum: $errstr\n";
153 }
154  
155 0 return;
156 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
157  
158 # Handles child DIE'ing
159 0 ▶sub Got_CLOSED : State {
Subroutine Got_CLOSED: not called CC=2 SCAR=17.9
Pod undocumented
160 # Get rid of the wheel
161 0 undef $_[HEAP]->{'WHEEL'};
162  
163 # Did we pass this test or not?
164 0 ▶ if ( ! $_[HEAP]->{'test_failure'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_[3]{"test_failure"}) 0 0 0
165 0 push( @{ $_[HEAP]->{'found_loops'} }, $_[HEAP]->{'current_loop'} );
166 }
167  
168 # move on to the next loop
169 0 $_[KERNEL]->yield( 'find_loops' );
170 0 return;
171 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
172  
173 1 1;
174 __END__
« Benchmarker/SubProcess.pm ↑ Summary Benchmarker/Imager/BasicStatistics.pm »