Async/Coderef.pm

filter: Statementstmt 39.2% 11 / 28 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 33.3% 3 / 9 Podpod 100% 5 / 5 totaltotal 37.2% 19 / 51 CC 4 SCAR 13.2
CC
4
Cov
31%
new
6.0
call
6.0
DESTROY
6.0
CRAP 3.8
« Async/URL.pm ↑ Summary Async/Server.pm »
1 package RPC::Async::Coderef;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '1.05';
6  
7 =head1 NAME
8  
9 RPC::Async::Coderef - wrapper class to ensure that coderefs are unmapped and
10 discarded on the client side when garbage collected on the server side
11  
12 =cut
13  
14 1 ▶use IO::EventMux;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 =head1 METHODS
17  
18 =head2 B<new($id)>
19  
20 Constructs a new coderef object.
21  
22 =cut
23  
24 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
25 0 my ($class, $id) = @_;
26  
27 0 my %self = (
28 id => $id,
29 call => undef,
30 destroy => undef,
31 );
32  
33 0 ▶ return bless \%self, (ref $class || $class);
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
34 }
35  
36 =head2 B<id()>
37  
38 Return id
39  
40 =cut
41  
42 0 ▶sub id {
Subroutine id: not called CC=1 SCAR=6.9
Pod documented
43 0 my ($self) = @_;
44 0 $self->{id};
45 }
46  
47 =head2 B<set_call($call)>
48  
49 Set callback function
50  
51 =cut
52  
53 0 ▶sub set_call {
Subroutine set_call: not called CC=1 SCAR=6.9
Pod documented
54 0 my ($self, $call) = @_;
55 0 $self->{call} = $call;
56 }
57  
58 =head2 B<set_destroy($destroy)>
59  
60 Set destroy function
61  
62 =cut
63  
64 0 ▶sub set_destroy {
Subroutine set_destroy: not called CC=1 SCAR=6.9
Pod documented
65 0 my ($self, $destroy) = @_;
66 0 $self->{destroy} = $destroy;
67 }
68  
69 =head2 B<call(@args)>
70  
71 Call callback function with @args
72  
73 =cut
74  
75 0 ▶sub call {
Subroutine call: not called CC=2 SCAR=17.9
Pod documented
76 0 my ($self, @args) = @_;
77 0 ▶ if ($self->{call}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'call'}) { } 0 0 0
78 0 $self->{call}->(@args);
79 } else {
80 0 die __PACKAGE__.": callback not set";
81 }
82 }
83  
84 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=2 SCAR=17.9
85 0 my ($self) = @_;
86 0 ▶ if ($self->{destroy}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"destroy"}) 0 0 0
87 0 $self->{destroy}->();
88 0 $self->{destroy} = undef;
89 }
90 }
91  
92 1 1;
93  
94 =head1 AUTHOR
95  
96 Troels Liebe Bentsen <tlb@rapanden.dk>, Jonas Jensen <jbj@knef.dk>
97  
98 =head1 COPYRIGHT
99  
100 Copyright(C) 2005-2007 Troels Liebe Bentsen
101 Copyright(C) 2005-2007 Jonas Jensen
102  
103 This library is free software; you can redistribute it and/or modify
104 it under the same terms as Perl itself.
105  
106 =cut
107  
108 # vim: et sw=4 sts=4 tw=80
« Async/URL.pm ↑ Summary Async/Server.pm »