| 1 | package POE::Component::DirWatch::Role::AIO; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | our $VERSION = "0.300001"; | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use POE; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use IO::AIO qw/2/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use POE::Component::AIO { no_auto_export => 1, no_auto_bootstrap => 1 }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Path::Class qw(file dir); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | has aio => ( | ||||||||||||||||||||||||||||
| 12 | is => 'ro', | ||||||||||||||||||||||||||||
| 13 | isa => 'POE::Component::AIO', | ||||||||||||||||||||||||||||
| 14 | required => 1, | ||||||||||||||||||||||||||||
| 15 | clearer => 'clear_aio', | ||||||||||||||||||||||||||||
| 16 | 3 | ▶ | default => sub { POE::Component::AIO->new } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 4 | ); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | after _start => sub { | ||||||||||||||||||||||||||||
| 20 | 3 | ▶ | my $self = $_[OBJECT]; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=1.0
| |||||||||||||||||||||||||||||
| 21 | my $aio_cb = sub { | ||||||||||||||||||||||||||||
| 22 | 9 | ▶ | my ($kernel, $dirs, $nondirs) = @_[KERNEL, ARG0, ARG1]; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=31.7
| |||||||||||||||||||||||||||||
| 23 | 9 | ▶ | my $filter = $self->has_filter ? $self->filter : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 9 | ▶ | if( $self->has_dir_callback ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 0 | foreach my $child (@$dirs){ | |||||||||||||||||||||||||||
| 26 | 0 | $child = dir($self->directory, $child); | |||||||||||||||||||||||||||
| 27 | 0 | ▶ | next if ref $filter && !$filter->($child); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $filter and not &$filter($child)
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)
| |||||||||||||||||||||||||||||
| 28 | 0 | $kernel->yield(dir_callback => $child); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | 9 | ▶ | if( $self->has_file_callback ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 9 | foreach my $child (@$nondirs){ | |||||||||||||||||||||||||||
| 33 | 14 | $child = file($self->directory, $child); | |||||||||||||||||||||||||||
| 34 | 14 | ▶ | next if ref $filter && !$filter->($child); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $filter and not &$filter($child)
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)
| |||||||||||||||||||||||||||||
| 35 | 14 | $poe_kernel->yield(file_callback => $child); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 9 | $self->next_poll( $kernel->delay_set(poll => $self->interval) ); | |||||||||||||||||||||||||||
| 39 | 3 | }; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 3 | $_[KERNEL]->state(aio_callback => $aio_cb); | |||||||||||||||||||||||||||
| 42 | 4 | }; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | around _poll => sub { | ||||||||||||||||||||||||||||
| 45 | 9 | ▶ | my $super = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | 9 | my ($self, $kernel) = @_[OBJECT, KERNEL]; | |||||||||||||||||||||||||||
| 47 | 9 | $self->clear_next_poll; | |||||||||||||||||||||||||||
| 48 | 9 | my $dir = $self->directory->stringify; | |||||||||||||||||||||||||||
| 49 | 9 | aio_scandir $dir, 0, $self->aio->postback('aio_callback'); | |||||||||||||||||||||||||||
| 50 | 4 | }; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | before _shutdown => sub { | ||||||||||||||||||||||||||||
| 53 | 3 | ▶ | my ($self, $kernel) = @_[OBJECT, KERNEL]; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | 3 | $kernel->state('aio_callback'); | |||||||||||||||||||||||||||
| 55 | 3 | $self->aio->shutdown; | |||||||||||||||||||||||||||
| 56 | 3 | $self->clear_aio; | |||||||||||||||||||||||||||
| 57 | 4 | }; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 4 | 1; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | __END__; | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | #--------#---------#---------#---------#---------#---------#---------#--------- | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =head1 NAME | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | POE::Component::DirWatch::Role::AIO - Make poll calls asynchronous | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | POE::Component::DirWatch::Role::AIO adds support for non-blocking polling | ||||||||||||||||||||||||||||
| 72 | operations using L<POE::Component::AIO> to interface with L<IO::AIO>. The | ||||||||||||||||||||||||||||
| 73 | L<POE::Component::AIO> object is stored in the C<aio> attribute, so you can | ||||||||||||||||||||||||||||
| 74 | access it in your own applications. | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =head2 aio | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | A read-only instance of POE::Component::AIO that is automatically created | ||||||||||||||||||||||||||||
| 81 | at instantiation time. | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head1 METHODS | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =head2 start | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | C<after '_start'> Create the C<aio_callback> event and event handler. | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =head2 _poll | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | C<around '_poll'> Replaces the original C<_poll> method with one that reads the | ||||||||||||||||||||||||||||
| 92 | contents of the target directory asynchronously. The original sub is never | ||||||||||||||||||||||||||||
| 93 | called. | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | L<POE::Component::DirWatch>, L<Moose> | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | Copyright 2006-2008 Guillermo Roditi. This is free software; you may | ||||||||||||||||||||||||||||
| 102 | redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =cut | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||