Peer/Subscription.pm

filter: Statementstmt 100% 31 / 31 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 100% 43 / 43 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Peer/Ephemeral.pm ↑ Summary Peer/Subscription/Ephemeral.pm »
1 # ABSTRACT: A Net::Object::Peer Subscription
2 package Net::Object::Peer::Subscription;
3  
4 23 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 23 ▶use Scalar::Util qw[ weaken refaddr ];
Subroutine BEGIN: called CC=1 SCAR=0.0
7 23 ▶use Types::Standard qw[ ConsumerOf Str CodeRef InstanceOf ];
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 23 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 23 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 23 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 23 our $VERSION = '0.06'; # TRIAL
14  
15  
16 #pod =attr peer
17 #pod
18 #pod A weak reference to the peer object subscribed to.
19 #pod
20 #pod =cut
21  
22 23 has peer => (
23 is => 'ro',
24 weak_ref => 1,
25 required => 1,
26 isa => ConsumerOf ['Net::Object::Peer'],
27 );
28  
29 #pod =attr addr
30 #pod
31 #pod The address returned by L<Scalar::Util::refaddr|Scalar::Util/refaddr> for
32 #pod the L</peer> attribute.
33 #pod
34 #pod =cut
35  
36 23 has addr => (
37 is => 'rwp',
38 isa => InstanceOf['Net::Object::Peer::RefAddr'],
39 init_arg => undef,
40 );
41  
42 #pod =attr name
43 #pod
44 #pod The name of the event listened for.
45 #pod
46 #pod =cut
47  
48 23 has name => (
49 is => 'ro',
50 isa => Str,
51 required => 1,
52 );
53  
54 23 has _unsubscribe => (
55 is => 'ro',
56 init_arg => 'unsubscribe',
57 isa => CodeRef,
58 required => 1,
59 );
60  
61  
62 #pod =begin pod_coverage
63 #pod
64 #pod =head3 BUILD
65 #pod
66 #pod =end pod_coverage
67 #pod
68 #pod =cut
69  
70 100 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod documented
71  
72 100 my $self = shift;
73  
74 100 $self->_set_addr( Net::Object::Peer::RefAddr->new( $self->peer ) );
75 }
76  
77 #pod =method unsubscribe
78 #pod
79 #pod =cut
80  
81 61 ▶sub unsubscribe { $_[0]->_unsubscribe->() }
Subroutine unsubscribe: called CC=1 SCAR=0.0
Pod documented
82  
83 #pod =method as_hashref
84 #pod
85 #pod $hashref = $sub->as_hashref;
86 #pod
87 #pod Return non-code attributes as a hash
88 #pod
89 #pod =cut
90  
91 90 ▶sub as_hashref {
Subroutine as_hashref: called CC=1 SCAR=0.0
Pod documented
92  
93 90 my $self = shift;
94  
95 90 my %hash = map { $_ => $self->$_ } qw[ peer name addr ];
96  
97 90 weaken $hash{peer};
98  
99 90 return \%hash;
100 }
101  
102 23 1;
103  
104 #
105 # This file is part of Net-Object-Peer
106 #
107 # This software is Copyright (c) 2016 by Smithsonian Astrophysical Observatory.
108 #
109 # This is free software, licensed under:
110 #
111 # The GNU General Public License, Version 3, June 2007
112 #
113  
114 =pod
115  
116 =head1 NAME
117  
118 Net::Object::Peer::Subscription - A Net::Object::Peer Subscription
119  
120 =head1 VERSION
121  
122 version 0.06
123  
124 =head1 DESCRIPTION
125  
126 A B<Net::Object::Peer::Subscription> object manages a node's
127 subscription to an emitter.
128  
129 It keeps a weak reference to the emitter so that the emitter will
130 disappear after it's defining scope has been destroyed.
131  
132 =head1 ATTRIBUTES
133  
134 =head2 peer
135  
136 A weak reference to the peer object subscribed to.
137  
138 =head2 addr
139  
140 The address returned by L<Scalar::Util::refaddr|Scalar::Util/refaddr> for
141 the L</peer> attribute.
142  
143 =head2 name
144  
145 The name of the event listened for.
146  
147 =head1 METHODS
148  
149 =head2 unsubscribe
150  
151 =head2 as_hashref
152  
153 $hashref = $sub->as_hashref;
154  
155 Return non-code attributes as a hash
156  
157 =begin pod_coverage
158  
159 =head3 BUILD
160  
161 =end pod_coverage
162  
163 =head1 AUTHOR
164  
165 Diab Jerius <djerius@cpan.org>
166  
167 =head1 COPYRIGHT AND LICENSE
168  
169 This software is Copyright (c) 2016 by Smithsonian Astrophysical Observatory.
170  
171 This is free software, licensed under:
172  
173 The GNU General Public License, Version 3, June 2007
174  
175 =cut
176  
177 __END__
« Peer/Ephemeral.pm ↑ Summary Peer/Subscription/Ephemeral.pm »