| 1 | package AnyEvent::Subprocess::Running::Delegate; | ||||||||||||||||||||||||||||
| 2 | 48 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 48 | $AnyEvent::Subprocess::Running::Delegate::VERSION = '1.102912'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | # ABSTRACT: delegate on the running process class | ||||||||||||||||||||||||||||
| 6 | 48 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 47 | with 'AnyEvent::Subprocess::Delegate'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 47 | has 'event_senders' => ( | |||||||||||||||||||||||||||
| 11 | is => 'rw', | ||||||||||||||||||||||||||||
| 12 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 13 | predicate => 'has_event_senders', | ||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # you can call this before event_senders are vivified | ||||||||||||||||||||||||||||
| 17 | 94 | ▶ | sub event_sender_for { | ||||||||||||||||||||||||||
|
Subroutine
event_sender_for: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 94 | my ($self, $event) = @_; | |||||||||||||||||||||||||||
| 19 | 74 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 74 | my $val = shift; | |||||||||||||||||||||||||||
| 21 | 74 | $self->send_event($event, $val); | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | 94 | } | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 74 | ▶ | sub send_event { | ||||||||||||||||||||||||||
|
Subroutine
send_event: called CC=4 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 74 | my ($self, $event, $value) = @_; | |||||||||||||||||||||||||||
| 27 | 74 | ▶ | confess "No event senders set yet!" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | unless $self->has_event_senders; | ||||||||||||||||||||||||||||
| 29 | 74 | my $sender = $self->event_senders->{$event}; | |||||||||||||||||||||||||||
| 30 | 74 | ▶ | confess "No event sender '$event' found" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$sender and ref $sender
MC/DC0%0/2
$sender and ref $sender
$sender
ref $sender
Truth table33%1/3
A and B
A= $senderB= ref $sender
| |||||||||||||||||||||||||||||
| 31 | unless $sender && ref $sender; | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 74 | $sender->($value); | |||||||||||||||||||||||||||
| 34 | 74 | return; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 47 | requires 'build_events'; | |||||||||||||||||||||||||||
| 38 | 47 | requires 'build_done_delegates'; | |||||||||||||||||||||||||||
| 39 | 47 | requires 'completion_hook'; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 47 | 1; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =pod | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =head1 NAME | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | AnyEvent::Subprocess::Running::Delegate - delegate on the running process class | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =head1 VERSION | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | version 1.102912 | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =head1 REQUIRED METHODS | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | Delegates must implement these methods: | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =head2 build_events | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | Return a list of events that need to be sent before the run will be | ||||||||||||||||||||||||||||
| 62 | considered complete | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =head2 build_done_delegates | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | Return a list of delegates to be passed to the "done" instance. | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =head2 completion_hook | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | Called after all events are received but before calling the final | ||||||||||||||||||||||||||||
| 71 | C<on_complete> method. | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =head1 METHODS | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =head2 event_sender_for($name) | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | Returns the event sender coderef for the event named C<$name>. | ||||||||||||||||||||||||||||
| 78 | C<$name> should have been returned by C<build_events>, otherwise this | ||||||||||||||||||||||||||||
| 79 | will break. | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =head2 send_event($name, $value) | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | Method that works like calling the coderef returned by | ||||||||||||||||||||||||||||
| 84 | C<event_sender_for($name)>. | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | Jonathan Rockway <jrockway@cpan.org> | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | This software is copyright (c) 2011 by Jonathan Rockway. | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 95 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =cut | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | __END__ | ||||||||||||||||||||||||||||