Declare/Meta/Timeout.pm

filter: Statementstmt 100% 24 / 24 Branchbran n/a Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 91.6% 33 / 36 CC 2 SCAR 2.0
CC
2
Cov
96%
as_perl
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« Declare/Meta.pm ↑ Summary Declare/Meta/Slot.pm »
1 package POE::Declare::Meta::Timeout;
2  
3 =pod
4  
5 =head1 NAME
6  
7 POE::Declare::Meta::Timeout - A named timeout with generated support methods
8  
9 =head1 SYNOPSIS
10  
11 # Send a request
12 sub request : Event {
13 $_[SELF]->request_timeout_start;
14 $_[SELF]->{handle}->put('something');
15 }
16
17 # Received a response
18 sub response : Event {
19 if ( $_[ARG0] eq 'keepalive' ) {
20 $_[SELF]->request_timeout_restart;
21 return;
22 }
23
24 $_[SELF]->request_timeout_stop;
25 $_[SELF]->{parent}->post('child_response', $_[ARG0]);
26 }
27
28 # Did not get a response
29 sub request_timeout : Timeout(30) {
30 # Take some action
31 $_[SELF]->cleanup;
32 $_[SELF]->{parent}->post('child_response', 'timeout');
33 }
34  
35 =head1 DESCRIPTION
36  
37 B<POE::Declare::Meta::Timeout> is a sub-class of C<Event> with access to
38 a number of additional methods relating to timers and alarms.
39  
40 =cut
41  
42 5 ▶use 5.008007;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 5 ▶use POE::Declare::Meta::Event ();
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 5 ▶use vars qw{$VERSION @ISA};
Subroutine BEGIN: called CC=1 SCAR=0.0
48 5 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
49 5 $VERSION = '0.59';
50 5 @ISA = 'POE::Declare::Meta::Event';
51 }
52  
53 5 ▶use Class::XSAccessor {
Subroutine BEGIN: called CC=1 SCAR=0.0
54 5 getters => {
55 delay => 'delay',
56 variance => 'variance',
57 },
58 5 };
59  
60  
61  
62  
63  
64 #####################################################################
65 # Main Methods
66  
67 1 ▶sub as_perl {
Subroutine as_perl: called CC=2 SCAR=7.0
Pod undocumented
68 1 my $name = $_[0]->{name};
69 1 my $delay = $_[0]->{delay};
70 1 ▶ my $variance = $_[0]->{variance} || 0;
Condition50%1/2
$_[0]{'variance'} || 0
l!l
01
MC/DC0%0/1
$_[0]{'variance'} || 0
$_[0]{'variance'}
Truth table50%1/2
A
A= $_[0]{'variance'}
Aresult
11
00
71 1 return <<"END_PERL";
72 sub ${name}_start {
73 my \$delay = \@_ > 1 ? defined \$_[1] ? \$_[1] : $delay : $delay;
74 my \$variance = \@_ > 1 ? \$_[2] || $variance : $variance;
75 \$poe_kernel->delay(
76 '$name' => \$delay + rand(\$variance * 2) - \$variance
77 ) or return;
78 die("Failed to create timeout for event '$name'");
79 }
80  
81 *${name}_restart = *${name}_start;
82  
83 sub ${name}_stop {
84 my \$self = (\@_ == 1) ? \$_[0] : \$_[HEAP];
85 \$poe_kernel->delay( '$name' ) or return;
86 die("Failed to create timeout for event '$name'");
87 }
88 END_PERL
89 }
90  
91 5 1;
92  
93 =pod
94  
95 =head1 SUPPORT
96  
97 Bugs should be always be reported via the CPAN bug tracker at
98  
99 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE-Declare>
100  
101 For other issues, or commercial enhancement or support, contact the author.
102  
103 =head1 AUTHORS
104  
105 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
106  
107 =head1 SEE ALSO
108  
109 L<POE>, L<POE::Declare>
110  
111 =head1 COPYRIGHT
112  
113 Copyright 2006 - 2012 Adam Kennedy.
114  
115 This program is free software; you can redistribute
116 it and/or modify it under the same terms as Perl itself.
117  
118 The full text of the license can be found in the
119 LICENSE file included with this module.
120  
121 =cut
« Declare/Meta.pm ↑ Summary Declare/Meta/Slot.pm »