blib/lib/POE/Component/IRC/Plugin/Role.pm

filter: Statementstmt 100% 30 / 30 Branchbran 50.0% 2 / 4 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 81.1% 43 / 53 CC 5 SCAR 11.6
CC
5
Cov
85%
PCI_register
5.8
BEGIN
1.0
BEGIN
1.0
CRAP 3.2
↑ Summary
1 package POE::Component::IRC::Plugin::Role;
2 3 $POE::Component::IRC::Plugin::Role::VERSION = '0.08';
3 #ABSTRACT: A Moose role for POE::Component::IRC plugins
4  
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 has 'irc' => (
9 is => 'ro',
10 isa => 'POE::Component::IRC',
11 writer => 'set_irc',
12 clearer => 'clear_irc',
13 init_arg => undef,
14 );
15  
16 3 has 'S_events' => (
17 is => 'ro',
18 isa => 'ArrayRef',
19 auto_deref => 1,
20 lazy_build => 1,
21 builder => '_default_sevents',
22 );
23  
24 3 has 'U_events' => (
25 is => 'ro',
26 isa => 'ArrayRef',
27 auto_deref => 1,
28 lazy_build => 1,
29 builder => '_default_uevents',
30 );
31  
32 sub _default_sevents {
33 1 ▶ [ grep { s/S_(\w+)/$1/ } shift->meta->get_all_method_names ];
Subroutine _default_sevents: called CC=1 SCAR=0.0
34 }
35  
36 sub _default_uevents {
37 1 ▶ [ grep { s/S_(\w+)/$1/ } shift->meta->get_all_method_names ];
Subroutine _default_uevents: called CC=1 SCAR=0.0
38 }
39  
40 sub PCI_register {
41 1 ▶ my ($self, $irc) = splice @_, 0, 2;
Subroutine PCI_register: called CC=5 SCAR=17.6
Pod documented
42 1 $self->set_irc( $irc );
43 1 ▶ if ( $self->S_events and scalar @{ $self->S_events } > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->S_events and scalar @{$self->S_events;} > 0) 1 0 1
Condition33%1/3
$self->S_events and scalar @{$self->S_events;} > 0
!ll&&!rl&&r
001
MC/DC0%0/2
$self->S_events and scalar @{$self->S_events;} > 0
$self->S_events scalar @{$self->S_events;} > 0
Truth table33%1/3
A and B
A= $self->S_eventsB= scalar @{$self->S_events;} > 0
ABresult
0X0
100
111
44 1 $irc->plugin_register( $self, 'SERVER', $self->S_events );
45 }
46 1 ▶ if ( $self->U_events and scalar @{ $self->U_events } > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->U_events and scalar @{$self->U_events;} > 0) 1 0 1
Condition33%1/3
$self->U_events and scalar @{$self->U_events;} > 0
!ll&&!rl&&r
001
MC/DC0%0/2
$self->U_events and scalar @{$self->U_events;} > 0
$self->U_events scalar @{$self->U_events;} > 0
Truth table33%1/3
A and B
A= $self->U_eventsB= scalar @{$self->U_events;} > 0
ABresult
0X0
100
111
47 1 $irc->plugin_register( $self, 'USER', $self->U_events );
48 }
49 1 return 1;
50 }
51  
52 sub PCI_unregister {
53 1 ▶ my $self = shift;
Subroutine PCI_unregister: called CC=1 SCAR=0.0
Pod documented
54 1 $self->clear_irc;
55 1 return 1;
56 }
57  
58 3 ▶no Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
59  
60 3 'Moosified Plugins ahoy!'
61  
62 __END__
63  
64 =pod
65  
66 =encoding UTF-8
67  
68 =head1 NAME
69  
70 POE::Component::IRC::Plugin::Role - A Moose role for POE::Component::IRC plugins
71  
72 =head1 VERSION
73  
74 version 0.08
75  
76 =head1 SYNOPSIS
77  
78 package My::Plugin;
79  
80 use Moose;
81 use POE::Component::IRC::Plugin qw(:ALL);
82  
83 with 'POE::Component::IRC::Plugin::Role';
84  
85 # PCI_register and PCI_unregister are automatically dealt with
86  
87 sub S_001 {
88 my $self = shift;
89 $self->irc->yield( 'join', '#channel' );
90 return PCI_EAT_NONE;
91 }
92  
93 1;
94  
95 =head1 DESCRIPTION
96  
97 POE::Component::IRC::Plugin::Role is a L<Moose> role that encapsulates some of the boilerplate
98 required to write L<POE::Component::IRC> plugins with L<Moose>.
99  
100 Simply consume the role in your L<Moose> based plugins.
101  
102 =for Pod::Coverage PCI_register PCI_ungreister
103  
104 =head1 ATTRIBUTES
105  
106 =over
107  
108 =item C<irc>
109  
110 Should be a L<POE::Component::IRC> object. It can not be set in the constructor, but has C<set_irc> and C<clear_irc>
111 writer and clearer methods, respectively. It is usually set for you by C<PCI_register> and cleared by C<PCI_unregister>
112 methods.
113  
114 =item C<S_events>
115  
116 An arrayref of C<SERVER> events to register for when C<PCI_Register> is called. The default is to register events for
117 the C<S_*> prefixed methods in your module.
118  
119 =item C<U_events>
120  
121 An arrayref of C<USER> events to register for when C<PCI_register> is called. The default is to register events for
122 the C<U_*> prefixed methods in your module.
123  
124 =back
125  
126 =head1 METHODS
127  
128 =over
129  
130 =item C<PCI_register>
131  
132 This is called everytime a plugin object is added to L<POE::Component::IRC>. It will set the C<irc> attribute
133 and register for the requested C<S_events> and C<U_events>.
134  
135 =item C<PCI_unregister>
136  
137 This is called everytime a plugin object is removed from L<POE::Component::IRC>. It will clear the C<irc> attribute.
138  
139 =back
140  
141 =head1 SEE ALSO
142  
143 L<POE::Component::IRC>
144  
145 L<POE::Component::IRC::Plugin>
146  
147 L<Moose::Role>
148  
149 =head1 AUTHORS
150  
151 =over 4
152  
153 =item *
154  
155 Chris Williams <chris@bingosnet.co.uk>
156  
157 =item *
158  
159 Chris Prather
160  
161 =item *
162  
163 Shawn M Moore
164  
165 =back
166  
167 =head1 COPYRIGHT AND LICENSE
168  
169 This software is copyright (c) 2017 by Chris Williams.
170  
171 This is free software; you can redistribute it and/or modify it under
172 the same terms as the Perl 5 programming language system itself.
173  
174 =cut
↑ Summary