| 1 | package MooseX::POE::Meta::Trait::Object; | ||||||||||||
| 2 | { | ||||||||||||
| 3 | 16 | $MooseX::POE::Meta::Trait::Object::VERSION = '0.215'; | |||||||||||
| 4 | } | ||||||||||||
| 5 | # ABSTRACT: The base class role for MooseX::POE | ||||||||||||
| 6 | |||||||||||||
| 7 | 16 | ▶ | use Moose::Role; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 16 | ▶ | use POE::Session; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 50 | ▶ | sub BUILD { | ||||||||||
|
Subroutine
BUILD: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 11 | 50 | my $self = shift; | |||||||||||
| 12 | |||||||||||||
| 13 | my $session = POE::Session->create( | ||||||||||||
| 14 | inline_states => | ||||||||||||
| 15 | 50 | ▶ | { _start => sub { POE::Kernel->yield('STARTALL', \$_[5] ) }, }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | object_states => [ | ||||||||||||
| 17 | $self => { | ||||||||||||
| 18 | $self->meta->get_all_events, | ||||||||||||
| 19 | STARTALL => 'STARTALL', | ||||||||||||
| 20 | _stop => 'STOPALL', | ||||||||||||
| 21 | _child => 'CHILD', | ||||||||||||
| 22 | _parent => 'PARENT', | ||||||||||||
| 23 | _call_kernel_with_my_session => '_call_kernel_with_my_session', | ||||||||||||
| 24 | }, | ||||||||||||
| 25 | ], | ||||||||||||
| 26 | args => [$self], | ||||||||||||
| 27 | 50 | ▶ | heap => ( $self->{heap} ||= {} ), | ||||||||||
|
Condition100%2/2
$self->{"heap"} ||= {}
MC/DC100%1/1
$self->{"heap"} ||= {}
$self->{"heap"}
Truth table100%2/2
A
A= $self->{"heap"}
| |||||||||||||
| 28 | ); | ||||||||||||
| 29 | 50 | $self->{session_id} = $session->ID; | |||||||||||
| 30 | } | ||||||||||||
| 31 | |||||||||||||
| 32 | 109 | ▶ | sub get_session_id { | ||||||||||
|
Subroutine
get_session_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 33 | 109 | my ($self) = @_; | |||||||||||
| 34 | 109 | return $self->meta->get_meta_instance->get_session_id($self); | |||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | 79 | ▶ | sub yield { my $self = shift; POE::Kernel->post( $self->get_session_id, @_ ) } | ||||||||||
|
Subroutine
yield: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 38 | |||||||||||||
| 39 | 12 | ▶ | sub call { my $self = shift; POE::Kernel->call( $self->get_session_id, @_ ) } | ||||||||||
|
Subroutine
call: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 40 | |||||||||||||
| 41 | 3 | ▶ | sub _call_kernel_with_my_session { | ||||||||||
|
Subroutine
_call_kernel_with_my_session: called CC=1 SCAR=0.0
| |||||||||||||
| 42 | 3 | my ( $self, $function, @args ) = @_[ OBJECT, ARG0..$#_ ]; | |||||||||||
| 43 | 3 | POE::Kernel->$function( @args ); | |||||||||||
| 44 | } | ||||||||||||
| 45 | |||||||||||||
| 46 | 3 | ▶ | sub delay { my $self = shift; $self->call( _call_kernel_with_my_session => 'delay' => @_ ) } | ||||||||||
|
Subroutine
delay: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 47 | 0 | ▶ | sub alarm { my $self = shift; $self->call( _call_kernel_with_my_session => 'alarm', @_ ) } | ||||||||||
|
Subroutine
alarm: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 48 | 0 | ▶ | sub alarm_add { my $self = shift; $self->call( _call_kernel_with_my_session => 'alarm_add', @_ ) } | ||||||||||
|
Subroutine
alarm_add: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 49 | 0 | ▶ | sub delay_add { my $self = shift; $self->call( _call_kernel_with_my_session => 'delay_add', @_ ) } | ||||||||||
|
Subroutine
delay_add: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 50 | 0 | ▶ | sub alarm_set { my $self = shift; $self->call( _call_kernel_with_my_session => 'alarm_set', @_ ) } | ||||||||||
|
Subroutine
alarm_set: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 51 | 0 | ▶ | sub alarm_adjust { my $self = shift; $self->call( _call_kernel_with_my_session => 'alarm_adjust', @_ ) } | ||||||||||
|
Subroutine
alarm_adjust: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 52 | 0 | ▶ | sub alarm_remove { my $self = shift; $self->call( _call_kernel_with_my_session => 'alarm_remove', @_ ) } | ||||||||||
|
Subroutine
alarm_remove: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 53 | 0 | ▶ | sub alarm_remove_all { my $self = shift; $self->call( _call_kernel_with_my_session => 'alarm_remove_all', @_ ) } | ||||||||||
|
Subroutine
alarm_remove_all: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 54 | 0 | ▶ | sub delay_set { my $self = shift; $self->call( _call_kernel_with_my_session => 'delay_set', @_ ) } | ||||||||||
|
Subroutine
delay_set: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 55 | 0 | ▶ | sub delay_adjust { my $self = shift; $self->call( _call_kernel_with_my_session => 'delay_adjust', @_ ) } | ||||||||||
|
Subroutine
delay_adjust: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 56 | |||||||||||||
| 57 | 47 | ▶ | sub STARTALL { | ||||||||||
|
Subroutine
STARTALL: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 58 | 47 | my ( $self, @params ) = @_; | |||||||||||
| 59 | 47 | $params[4] = pop @params; | |||||||||||
| 60 | 47 | foreach | |||||||||||
| 61 | my $method ( reverse $self->meta->find_all_methods_by_name('START') ) | ||||||||||||
| 62 | { | ||||||||||||
| 63 | 94 | $method->{code}->( $self, @params ); | |||||||||||
| 64 | } | ||||||||||||
| 65 | } | ||||||||||||
| 66 | |||||||||||||
| 67 | 73 | ▶ | sub STOPALL { | ||||||||||
|
Subroutine
STOPALL: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 68 | 73 | my ( $self, $params ) = @_; | |||||||||||
| 69 | 73 | foreach | |||||||||||
| 70 | my $method ( reverse $self->meta->find_all_methods_by_name('STOP') ) { | ||||||||||||
| 71 | 131 | $method->{code}->( $self, $params ); | |||||||||||
| 72 | } | ||||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | 47 | ▶ | sub START { } | ||||||||||
|
Subroutine
START: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 76 | 73 | ▶ | sub STOP { } | ||||||||||
|
Subroutine
STOP: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 77 | 2 | ▶ | sub CHILD { } | ||||||||||
|
Subroutine
CHILD: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 78 | 0 | ▶ | sub PARENT { } | ||||||||||
|
Subroutine
PARENT: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 79 | |||||||||||||
| 80 | # __PACKAGE__->meta->add_method( _stop => sub { POE::Kernel->call('STOP') } ); | ||||||||||||
| 81 | |||||||||||||
| 82 | 16 | ▶ | __PACKAGE__->meta->add_method( | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 83 | _default => __PACKAGE__->meta->get_method('DEFAULT') ) | ||||||||||||
| 84 | if __PACKAGE__->meta->has_method('DEFAULT'); | ||||||||||||
| 85 | |||||||||||||
| 86 | 16 | ▶ | __PACKAGE__->meta->add_method( | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 87 | _child => __PACKAGE__->meta->get_method('CHILD') ) | ||||||||||||
| 88 | if __PACKAGE__->meta->has_method('CHILD'); | ||||||||||||
| 89 | |||||||||||||
| 90 | 16 | ▶ | __PACKAGE__->meta->add_method( | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 91 | _parent => __PACKAGE__->meta->get_method('PARENT') ) | ||||||||||||
| 92 | if __PACKAGE__->meta->has_method('PARENT'); | ||||||||||||
| 93 | |||||||||||||
| 94 | 16 | ▶ | no Moose::Role; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 95 | |||||||||||||
| 96 | 16 | 1; | |||||||||||
| 97 | |||||||||||||
| 98 | |||||||||||||
| 99 | |||||||||||||
| 100 | =pod | ||||||||||||
| 101 | |||||||||||||
| 102 | =head1 NAME | ||||||||||||
| 103 | |||||||||||||
| 104 | MooseX::POE::Meta::Trait::Object - The base class role for MooseX::POE | ||||||||||||
| 105 | |||||||||||||
| 106 | =head1 VERSION | ||||||||||||
| 107 | |||||||||||||
| 108 | version 0.215 | ||||||||||||
| 109 | |||||||||||||
| 110 | =head1 SYNOPSIS | ||||||||||||
| 111 | |||||||||||||
| 112 | package Counter; | ||||||||||||
| 113 | use MooseX::Poe; | ||||||||||||
| 114 | |||||||||||||
| 115 | has name => ( | ||||||||||||
| 116 | isa => 'Str', | ||||||||||||
| 117 | is => 'rw', | ||||||||||||
| 118 | default => sub { 'Foo ' }, | ||||||||||||
| 119 | ); | ||||||||||||
| 120 | |||||||||||||
| 121 | has count => ( | ||||||||||||
| 122 | isa => 'Int', | ||||||||||||
| 123 | is => 'rw', | ||||||||||||
| 124 | lazy => 1, | ||||||||||||
| 125 | default => sub { 0 }, | ||||||||||||
| 126 | ); | ||||||||||||
| 127 | |||||||||||||
| 128 | sub START { | ||||||||||||
| 129 | my ($self) = @_; | ||||||||||||
| 130 | $self->yield('increment'); | ||||||||||||
| 131 | } | ||||||||||||
| 132 | |||||||||||||
| 133 | sub increment { | ||||||||||||
| 134 | my ($self) = @_; | ||||||||||||
| 135 | $self->count( $self->count + 1 ); | ||||||||||||
| 136 | $self->yield('increment') unless $self->count > 3; | ||||||||||||
| 137 | } | ||||||||||||
| 138 | |||||||||||||
| 139 | no MooseX::Poe; | ||||||||||||
| 140 | |||||||||||||
| 141 | =head1 DESCRIPTION | ||||||||||||
| 142 | |||||||||||||
| 143 | MooseX::POE::Meta::TraitObject is a role that is applied to the object base | ||||||||||||
| 144 | classe (usually Moose::Object) that implements a POE::Session. | ||||||||||||
| 145 | |||||||||||||
| 146 | =head1 METHODS | ||||||||||||
| 147 | |||||||||||||
| 148 | =head2 get_session_id | ||||||||||||
| 149 | |||||||||||||
| 150 | Get the internal POE Session ID, this is useful to hand to other POE aware | ||||||||||||
| 151 | functions. | ||||||||||||
| 152 | |||||||||||||
| 153 | =head2 yield | ||||||||||||
| 154 | |||||||||||||
| 155 | =head2 call | ||||||||||||
| 156 | |||||||||||||
| 157 | =head2 delay | ||||||||||||
| 158 | |||||||||||||
| 159 | =head2 alarm | ||||||||||||
| 160 | |||||||||||||
| 161 | =head2 alarm_add | ||||||||||||
| 162 | |||||||||||||
| 163 | =head2 delay_add | ||||||||||||
| 164 | |||||||||||||
| 165 | =head2 alarm_set | ||||||||||||
| 166 | |||||||||||||
| 167 | =head2 alarm_adjust | ||||||||||||
| 168 | |||||||||||||
| 169 | =head2 alarm_remove | ||||||||||||
| 170 | |||||||||||||
| 171 | =head2 alarm_remove_all | ||||||||||||
| 172 | |||||||||||||
| 173 | =head2 delay_set | ||||||||||||
| 174 | |||||||||||||
| 175 | =head2 delay_adjust | ||||||||||||
| 176 | |||||||||||||
| 177 | A cheap alias for the same POE::Kernel function which will gurantee posting to the object's session. | ||||||||||||
| 178 | |||||||||||||
| 179 | =head2 STARTALL | ||||||||||||
| 180 | |||||||||||||
| 181 | Along similar lines to Moose's C<BUILDALL> method which calls all the C<BUILD> | ||||||||||||
| 182 | methods, this function will call all the C<START> methods in your inheritance | ||||||||||||
| 183 | hierarchy automatically when POE first runs your session. (This corresponds to | ||||||||||||
| 184 | the C<_start> event from POE.) | ||||||||||||
| 185 | |||||||||||||
| 186 | =head2 STOPALL | ||||||||||||
| 187 | |||||||||||||
| 188 | Along similar lines to C<STARTALL>, but for C<STOP> instead. | ||||||||||||
| 189 | |||||||||||||
| 190 | =head2 START | ||||||||||||
| 191 | |||||||||||||
| 192 | =head2 STOP | ||||||||||||
| 193 | |||||||||||||
| 194 | =head2 DEFAULT | ||||||||||||
| 195 | |||||||||||||
| 196 | =head2 CHILD | ||||||||||||
| 197 | |||||||||||||
| 198 | =head2 PARENT | ||||||||||||
| 199 | |||||||||||||
| 200 | =head1 DEFAULT METHODS | ||||||||||||
| 201 | |||||||||||||
| 202 | =head1 PREDEFINED EVENTS | ||||||||||||
| 203 | |||||||||||||
| 204 | =head1 AUTHORS | ||||||||||||
| 205 | |||||||||||||
| 206 | =over 4 | ||||||||||||
| 207 | |||||||||||||
| 208 | =item * | ||||||||||||
| 209 | |||||||||||||
| 210 | Chris Prather <chris@prather.org> | ||||||||||||
| 211 | |||||||||||||
| 212 | =item * | ||||||||||||
| 213 | |||||||||||||
| 214 | Ash Berlin <ash@cpan.org> | ||||||||||||
| 215 | |||||||||||||
| 216 | =item * | ||||||||||||
| 217 | |||||||||||||
| 218 | Chris Williams <chris@bingosnet.co.uk> | ||||||||||||
| 219 | |||||||||||||
| 220 | =item * | ||||||||||||
| 221 | |||||||||||||
| 222 | Yuval (nothingmuch) Kogman | ||||||||||||
| 223 | |||||||||||||
| 224 | =item * | ||||||||||||
| 225 | |||||||||||||
| 226 | Torsten Raudssus <torsten@raudssus.de> L<http://www.raudssus.de/> | ||||||||||||
| 227 | |||||||||||||
| 228 | =back | ||||||||||||
| 229 | |||||||||||||
| 230 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 231 | |||||||||||||
| 232 | This software is copyright (c) 2010 by Chris Prather, Ash Berlin, Chris Williams, Yuval Kogman, Torsten Raudssus. | ||||||||||||
| 233 | |||||||||||||
| 234 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 235 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 236 | |||||||||||||
| 237 | =cut | ||||||||||||
| 238 | |||||||||||||
| 239 | |||||||||||||
| 240 | __END__ | ||||||||||||