| 1 | package POE::Component::IRC::Plugin::Role; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | our $VERSION = '0.06'; | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 4 | 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 | 4 | has 'S_events' => ( | |||||||||||||||||||||||||||
| 17 | is => 'ro', | ||||||||||||||||||||||||||||
| 18 | isa => 'ArrayRef', | ||||||||||||||||||||||||||||
| 19 | auto_deref => 1, | ||||||||||||||||||||||||||||
| 20 | lazy_build => 1, | ||||||||||||||||||||||||||||
| 21 | builder => '_default_sevents', | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 4 | 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
Condition33%1/3
$self->S_events and scalar @{$self->S_events;} > 0
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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$self->U_events and scalar @{$self->U_events;} > 0
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
| |||||||||||||||||||||||||||||
| 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 | 4 | ▶ | no Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 4 | 'Moosified Plugins ahoy!' | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | __END__ | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =head1 NAME | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | POE::Component::IRC::Plugin::Role - A Moose role for POE::Component::IRC plugins | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | package My::Plugin; | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | use Moose; | ||||||||||||||||||||||||||||
| 73 | use POE::Component::IRC::Plugin qw(:ALL); | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | with 'POE::Component::IRC::Plugin::Role'; | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # PCI_register and PCI_unregister are automatically dealt with | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | sub S_001 { | ||||||||||||||||||||||||||||
| 80 | my $self = shift; | ||||||||||||||||||||||||||||
| 81 | $self->irc->yield( 'join', '#channel' ); | ||||||||||||||||||||||||||||
| 82 | return PCI_EAT_NONE; | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 1; | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | POE::Component::IRC::Plugin::Role is a L<Moose> role that encapsulates some of the boilerplate | ||||||||||||||||||||||||||||
| 90 | required to write L<POE::Component::IRC> plugins with L<Moose>. | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | Simply consume the role in your L<Moose> based plugins. | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =over | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =item C<irc> | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 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> | ||||||||||||||||||||||||||||
| 101 | writer and clearer methods, respectively. It is usually set for you by C<PCI_register> and cleared by C<PCI_unregister> | ||||||||||||||||||||||||||||
| 102 | methods. | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =item C<S_events> | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | An arrayref of C<SERVER> events to register for when C<PCI_Register> is called. The default is to register events for | ||||||||||||||||||||||||||||
| 107 | the C<S_*> prefixed methods in your module. | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =item C<U_events> | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | An arrayref of C<USER> events to register for when C<PCI_register> is called. The default is to register events for | ||||||||||||||||||||||||||||
| 112 | the C<U_*> prefixed methods in your module. | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =back | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =head1 METHODS | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =over | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =item C<PCI_register> | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | This is called everytime a plugin object is added to L<POE::Component::IRC>. It will set the C<irc> attribute | ||||||||||||||||||||||||||||
| 123 | and register for the requested C<S_events> and C<U_events>. | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =item C<PCI_unregister> | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | This is called everytime a plugin object is removed from L<POE::Component::IRC>. It will clear the C<irc> attribute. | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | =back | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | Chris C<BinGOs> Williams <chris@bingosnet.co.uk> | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | Chris Prather | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | Shawn M Moore | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | Copyright E<copy> Chris Williams | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | This module may be used, modified, and distributed under the same terms as Perl itself. Please see the license that came with your Perl distribution for details. | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | L<POE::Component::IRC> | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | L<POE::Component::IRC::Plugin> | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | L<Moose::Role> | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =cut | ||||||||||||||||||||||||||||