Environ.pm

filter: Statementstmt 100% 67 / 67 Branchbran 88.4% 23 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 97.0% 100 / 103 CC 15 SCAR 16.3
CC
15
Cov
97%
register
7.0
send_event
7.0
__ANON__
3.0
CRAP 5.1
↑ Summary Environ/Config.pm »
1 package App::Environ;
2  
3 4 ▶use 5.008000;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 our $VERSION = '0.22';
8  
9 4 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 my %REGD_HANDLERS;
12 my %MODULES_IDX;
13  
14  
15 7 ▶sub register {
Subroutine register: called CC=7 SCAR=19.5
Pod documented
16 7 my $class = shift;
17 7 my $module_class = shift;
18 7 my %handlers = @_;
19  
20 7 ▶ unless ( defined $module_class ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $module_class) 1 6 7
21 1 croak 'Module class must be specified';
22 }
23  
24 6 ▶ unless ( exists $MODULES_IDX{$module_class} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $MODULES_IDX{$module_class}) 6 0 6
25 6 $MODULES_IDX{$module_class} = {};
26 }
27 6 my $events_idx = $MODULES_IDX{$module_class};
28  
29 6 ▶ while ( my ( $event_name, $handler ) = each %handlers ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %handlers) 20 6 26
30 20 ▶ next if exists $events_idx->{$event_name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $events_idx->{$event_name} 0 20 20
31  
32 20 $events_idx->{$event_name} = 1;
33 20 ▶ unless ( exists $REGD_HANDLERS{$event_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $REGD_HANDLERS{$event_name}) 13 7 20
34 13 $REGD_HANDLERS{$event_name} = [];
35 }
36 20 ▶ if ( $event_name =~ m/\:r$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event_name =~ /\:r$/) { } 8 12 20
37 8 unshift( @{ $REGD_HANDLERS{$event_name} }, $handler );
38 }
39 else {
40 12 push( @{ $REGD_HANDLERS{$event_name} }, $handler );
41 }
42 }
43  
44 6 return;
45 }
46  
47 8 ▶sub send_event {
Subroutine send_event: called CC=7 SCAR=19.5
Pod documented
48 8 my $class = shift;
49 8 my $event_name = shift;
50 8 ▶ my $cb = pop if ref( $_[-1] ) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "CODE" 2 6 8
51 8 my @args = @_;
52  
53 8 ▶ unless ( defined $event_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $event_name) 1 7 8
54 1 croak 'Event name must be specified';
55 }
56  
57 7 ▶ unless ( exists $REGD_HANDLERS{$event_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $REGD_HANDLERS{$event_name}) 1 6 7
58 1 ▶ $cb->() if defined $cb;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cb 0 1 1
59 1 return;
60 }
61  
62 6 my @handlers = @{ $REGD_HANDLERS{$event_name} };
63 6 ▶ if ( defined $cb ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cb) { } 2 4 6
64 2 $class->_process_async( \@handlers, \@args, $cb );
65 }
66 else {
67 4 foreach my $handler (@handlers) {
68 11 $handler->(@args);
69 }
70 }
71  
72 5 return;
73 }
74  
75 4 ▶sub _process_async {
Subroutine _process_async: called CC=1 SCAR=0.0
76 4 my $class = shift;
77 4 my $handlers = shift;
78 4 my $args = shift;
79 4 my $cb = shift;
80  
81 4 my $handler = shift @{$handlers};
82  
83 4 $handler->( @{$args},
84 4 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
85 4 my $err = shift;
86  
87 4 ▶ if ( defined $err ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $err) 1 3 4
88 1 $cb->($err);
89 1 return;
90 }
91  
92 3 ▶ if ( @{$handlers} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$handlers;}) 2 1 3
93 2 $class->_process_async( $handlers, $args, $cb );
94 2 return;
95 }
96  
97 1 $cb->();
98 }
99 4 );
100  
101 4 return;
102 }
103  
104 4 1;
105 __END__
↑ Summary Environ/Config.pm »