DirWatch.pm

filter: Statementstmt 84.8% 73 / 86 Branchbran 55.0% 22 / 40 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 70.0% 14 / 20 Podpod 100% 5 / 5 totaltotal 71.4% 115 / 161 CC 23 SCAR 19.1
CC
23
Cov
73%
_poll
17.6
shutdown
6.0
_resume
4.2
CRAP 6.7
« DirWatch/Unmodified.pm ↑ Summary DirWatch/Modified.pm »
1 package POE::Component::DirWatch;
2  
3 5 our $VERSION = "0.300004";
4  
5 5 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Class::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use MooseX::Types::Path::Class qw/Dir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 8 ▶sub import {
Subroutine import: called CC=4 SCAR=13.9
11 8 my ($class, %args) = @_;
12 8 ▶ return if delete $args{no_aio};
Branch: 1 branch
BranchTrueFalseTotal
if delete $args{"no_aio"} 1 7 8
13 7 ▶ return unless eval { Class::Load::load_class("POE::Component::AIO") };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { Class::Load::load_class("POE::Component::AIO") } } 0 7 7
14 7 ▶ if (eval { Class::Load::load_class("POE::Component::DirWatch::Role::AIO") }){
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { Class::Load::load_class("POE::Component::DirWatch::Role::AIO") } }) 7 0 7
15 7 $class->meta->make_mutable;
16 7 POE::Component::DirWatch::Role::AIO->meta->apply($class->meta);
17 7 $class->meta->make_immutable;
18 }
19 7 return;
20 }
21  
22 #--------#---------#---------#---------#---------#---------#---------#--------#
23  
24 5 has alias => (
25 is => 'ro',
26 isa => 'Str',
27 required => 1,
28 default => 'dirwatch'
29 );
30  
31 5 has directory => (
32 is => 'rw',
33 isa => Dir,
34 required => 1,
35 coerce => 1
36 );
37  
38 5 has interval => (
39 is => 'rw',
40 isa => 'Int',
41 required => 1
42 );
43  
44 5 has next_poll => (
45 is => 'rw',
46 isa => 'Int',
47 clearer => 'clear_next_poll',
48 predicate => 'has_next_poll'
49 );
50  
51 5 has filter => (
52 is => 'rw',
53 isa => 'CodeRef',
54 clearer => 'clear_filter',
55 predicate => 'has_filter'
56 );
57  
58 5 has dir_callback => (
59 is => 'rw',
60 isa => 'Ref',
61 clearer => 'clear_dir_callback',
62 predicate => 'has_dir_callback'
63 );
64  
65 5 has file_callback => (
66 is => 'rw',
67 isa => 'Ref',
68 clearer => 'clear_file_callback',
69 predicate => 'has_file_callback'
70 );
71  
72 4 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=12.0
Pod documented
73 4 my ($self, $args) = @_;
74 4 ▶ POE::Session->create(
Branch: 2 branches
BranchTrueFalseTotal
$self->has_dir_callback ? : 0 4 4
$self->has_file_callback ? : 4 0 4
75 object_states => [
76 $self,
77 {
78 _start => '_start',
79 _pause => '_pause',
80 _resume => '_resume',
81 _child => '_child',
82 _stop => '_stop',
83 shutdown => '_shutdown',
84 poll => '_poll',
85 ($self->has_dir_callback ? (dir_callback => '_dir_callback') : () ),
86 ($self->has_file_callback ? (file_callback => '_file_callback') : () ),
87 },
88 ]
89 );
90 }
91  
92 0 ▶sub session { $poe_kernel->alias_resolve( shift->alias ) }
Subroutine session: not called CC=1 SCAR=6.9
Pod documented
93  
94 #--------#---------#---------#---------#---------#---------#---------#---------
95  
96 4 ▶sub _start {
Subroutine _start: called CC=1 SCAR=0.0
97 4 my ($self, $kernel) = @_[OBJECT, KERNEL];
98 4 $kernel->alias_set($self->alias); # set alias for ourselves and remember it
99 4 $self->next_poll( $kernel->delay_set(poll => $self->interval) );
100 }
101  
102 3 ▶sub _pause {
Subroutine _pause: called CC=4 SCAR=14.0
103 3 my ($self, $kernel, $until) = @_[OBJECT, KERNEL, ARG0];
104 3 ▶ $kernel->alarm_remove($self->next_poll) if $self->has_next_poll;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_next_poll 3 0 3
105 3 $self->clear_next_poll;
106 3 ▶ return unless defined $until;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $until 2 1 3
107  
108 1 my $t = time;
109 1 ▶ $until += $t if $t > $until;
Branch: 1 branch
BranchTrueFalseTotal
if $t > $until 0 1 1
110 1 $self->next_poll( $kernel->alarm_set(poll => $until) );
111  
112 }
113  
114 2 ▶sub _resume {
Subroutine _resume: called CC=4 SCAR=14.3
115 2 my ($self, $kernel, $when) = @_[OBJECT, KERNEL, ARG0];
116 2 ▶ $kernel->alarm_remove($self->next_poll) if $self->has_next_poll;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_next_poll 0 2 2
117 2 $self->clear_next_poll;
118 2 ▶ $when = 0 unless defined $when;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $when 0 2 2
119  
120 2 my $t = time;
121 2 ▶ $when += $t if $t > $when;
Branch: 1 branch
BranchTrueFalseTotal
if $t > $when 0 2 2
122 2 $self->next_poll( $kernel->alarm_set(poll => $when) );
123 }
124  
125 4 ▶sub _stop {}
Subroutine _stop: called CC=1 SCAR=0.0
126  
127 0 ▶sub _child {}
Subroutine _child: not called CC=1 SCAR=0.0
128  
129 #--------#---------#---------#---------#---------#---------#---------#---------
130  
131 0 ▶sub pause {
Subroutine pause: not called CC=1 SCAR=6.9
Pod documented
132 0 my ($self, $until) = @_;
133 0 $poe_kernel->call($self->alias, _pause => $until);
134 }
135  
136 0 ▶sub resume {
Subroutine resume: not called CC=1 SCAR=6.9
Pod documented
137 0 my ($self, $when) = @_;
138 0 $poe_kernel->call($self->alias, _resume => $when);
139 }
140  
141 0 ▶sub shutdown {
Subroutine shutdown: not called CC=2 SCAR=17.9
Pod documented
142 0 my ($self) = @_;
143 0 ▶ $poe_kernel->alarm_remove($self->next_poll) if $self->has_next_poll;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_next_poll 0 0 0
144 0 $self->clear_next_poll;
145 0 $poe_kernel->post($self->alias, 'shutdown');
146 }
147  
148 #--------#---------#---------#---------#---------#---------#---------#---------
149  
150 2 ▶sub _poll {
Subroutine _poll: called CC=11 SCAR=28.7
151 2 my ($self, $kernel) = @_[OBJECT, KERNEL];
152 2 $self->clear_next_poll;
153  
154 #just do this part once per poll
155 2 ▶ my $filter = $self->has_filter ? $self->filter : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->has_filter ? : 0 2 2
156 2 my $has_dir_cb = $self->has_dir_callback;
157 2 my $has_file_cb = $self->has_file_callback;
158  
159 2 ▶ while (my $child = $self->directory->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $child = $self->directory->next) 8 2 10
160 8 ▶ if($child->is_dir){
Branch: 1 branch
BranchTrueFalseTotal
if ($child->is_dir) { } 4 4 8
161 4 ▶ next unless $has_dir_cb;
Branch: 1 branch
BranchTrueFalseTotal
unless $has_dir_cb 4 0 4
162 0 ▶ next if ref $filter && !$filter->($child);
Branch: 1 branch
BranchTrueFalseTotal
if ref $filter and not &$filter($child) 0 0 0
Condition0%0/3
ref $filter and not &$filter($child)
!ll&&!rl&&r
000
MC/DC0%0/2
ref $filter and not &$filter($child)
ref $filter not &$filter($child)
Truth table0%0/3
A and not(B)
A= ref $filterB= not &$filter($child)
ABresult
0X0
100
111
163 0 $kernel->yield(dir_callback => $child);
164 } else {
165 4 ▶ next unless $has_file_cb;
Branch: 1 branch
BranchTrueFalseTotal
unless $has_file_cb 0 4 4
166 4 ▶ next if $child->basename =~ /^\.+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $child->basename =~ /^\.+$/ 0 4 4
167 4 ▶ next if ref $filter && !$filter->($child);
Branch: 1 branch
BranchTrueFalseTotal
if ref $filter and not &$filter($child) 0 4 4
Condition33%1/3
ref $filter and not &$filter($child)
!ll&&!rl&&r
400
MC/DC0%0/2
ref $filter and not &$filter($child)
ref $filter not &$filter($child)
Truth table33%1/3
A and not(B)
A= ref $filterB= not &$filter($child)
ABresult
0X0
100
111
168 4 $kernel->yield(file_callback => $child);
169 }
170 }
171  
172 2 $self->next_poll( $kernel->delay_set(poll => $self->interval) );
173 }
174  
175 #these are only here so allow method modifiers to hook into them
176 #these are prime candidates for inlining when the class is made immutable
177 11 ▶sub _file_callback {
Subroutine _file_callback: called CC=1 SCAR=0.0
178 11 my ($self, $kernel, $file) = @_[OBJECT, KERNEL, ARG0];
179 11 $self->file_callback->($file);
180 }
181  
182 0 ▶sub _dir_callback {
Subroutine _dir_callback: not called CC=1 SCAR=6.9
183 0 my ($self, $kernel, $dir) = @_[OBJECT, KERNEL, ARG0];
184 0 $self->dir_callback->($dir);
185 }
186  
187 #--------#---------#---------#---------#---------#---------#---------#---------
188  
189 4 ▶sub _shutdown {
Subroutine _shutdown: called CC=1 SCAR=0.0
190 4 my ($self, $kernel, $heap) = @_[OBJECT, KERNEL, HEAP];
191 #cleaup heap, alias, alarms (no lingering refs n ish)
192 4 %$heap = ();
193 4 $kernel->alias_remove($self->alias);
194 4 $kernel->alarm_remove_all();
195 }
196  
197 #--------#---------#---------#---------#---------#---------#---------#---------
198  
199 5 __PACKAGE__->meta->make_immutable;
200  
201 5 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
202  
203 5 1;
204  
205 __END__;
« DirWatch/Unmodified.pm ↑ Summary DirWatch/Modified.pm »