| 1 | # ABSTRACT: A Node style event Role for Moose | ||||||||||||||
| 2 | package MooseX::Event; | ||||||||||||||
| 3 | { | ||||||||||||||
| 4 | 3 | $MooseX::Event::VERSION = 'v0.2.0'; | |||||||||||||
| 5 | } | ||||||||||||||
| 6 | 3 | ▶ | use Any::Moose (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 3 | ▶ | use Any::Moose '::Exporter'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | { | ||||||||||||||
| 10 | 3 | my($import,$unimport,$init_meta) = any_moose('::Exporter')->build_import_methods( | |||||||||||||
| 11 | as_is => [qw( has_event has_events )], | ||||||||||||||
| 12 | also => any_moose(), | ||||||||||||||
| 13 | ); | ||||||||||||||
| 14 | |||||||||||||||
| 15 | 3 | ▶ | sub import { | ||||||||||||
|
Subroutine
import: called CC=5 SCAR=17.1
| |||||||||||||||
| 16 | 3 | my $class = shift; | |||||||||||||
| 17 | |||||||||||||||
| 18 | 3 | my $with_args = {}; | |||||||||||||
| 19 | |||||||||||||||
| 20 | 3 | my @args; | |||||||||||||
| 21 | 3 | ▶ | while (local $_ = shift @_) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 22 | 1 | ▶ | if ( $_ eq '-alias' ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 23 | 1 | $with_args->{'-alias'} = shift; | |||||||||||||
| 24 | } | ||||||||||||||
| 25 | elsif ( $_ eq '-excludes' ) { | ||||||||||||||
| 26 | 0 | $with_args->{'-excludes'} = shift; | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | else { | ||||||||||||||
| 29 | 0 | push @args, $_; | |||||||||||||
| 30 | } | ||||||||||||||
| 31 | } | ||||||||||||||
| 32 | |||||||||||||||
| 33 | 3 | my $caller = caller(); | |||||||||||||
| 34 | 3 | $class->$import( { into => $caller }, @args ); | |||||||||||||
| 35 | |||||||||||||||
| 36 | # I would expect that 'base_class_roles' in setup_import_methods would | ||||||||||||||
| 37 | # do the below, but no, it doesn't. | ||||||||||||||
| 38 | 3 | ▶ | if ( ! any_moose('::Util')->can('does_role')->( $caller, 'MooseX::Event::Role' ) ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 39 | 3 | require MooseX::Event::Role; | |||||||||||||
| 40 | 3 | MooseX::Event::Role->meta->apply( $caller->meta, %{$with_args} ); | |||||||||||||
| 41 | } | ||||||||||||||
| 42 | } | ||||||||||||||
| 43 | |||||||||||||||
| 44 | 3 | ▶ | sub unimport { goto $unimport; } | ||||||||||||
|
Subroutine
unimport: called CC=1 SCAR=0.0
| |||||||||||||||
| 45 | 3 | ▶ | *init_meta = $init_meta if defined $init_meta; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 46 | } | ||||||||||||||
| 47 | |||||||||||||||
| 48 | |||||||||||||||
| 49 | 3 | our @listener_wrappers; | |||||||||||||
| 50 | |||||||||||||||
| 51 | |||||||||||||||
| 52 | 0 | ▶ | sub add_listener_wrapper { | ||||||||||||
|
Subroutine
add_listener_wrapper: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 53 | 0 | my( $wrapper ) = @_[1..$#_]; | |||||||||||||
| 54 | 0 | push @listener_wrappers, $wrapper; | |||||||||||||
| 55 | 0 | return $wrapper; | |||||||||||||
| 56 | } | ||||||||||||||
| 57 | |||||||||||||||
| 58 | |||||||||||||||
| 59 | 0 | ▶ | sub remove_listener_wrapper { | ||||||||||||
|
Subroutine
remove_listener_wrapper: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 60 | 0 | my( $wrapper ) = @_[1..$#_]; | |||||||||||||
| 61 | 0 | @listener_wrappers = grep { $_ != $wrapper } @listener_wrappers; | |||||||||||||
| 62 | 0 | return; | |||||||||||||
| 63 | } | ||||||||||||||
| 64 | |||||||||||||||
| 65 | |||||||||||||||
| 66 | |||||||||||||||
| 67 | |||||||||||||||
| 68 | 3 | ▶ | my $stub = sub {}; | ||||||||||||
|
Subroutine
event:new_listener: not called CC=1 SCAR=0.0
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||
| 69 | 6 | ▶ | sub has_event { | ||||||||||||
|
Subroutine
has_event: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 70 | 6 | my $class = caller(); | |||||||||||||
| 71 | 6 | $class->meta->add_method( "event:$_" => $stub ) for @_; | |||||||||||||
| 72 | } | ||||||||||||||
| 73 | |||||||||||||||
| 74 | 3 | ▶ | BEGIN { *has_events = \&has_event } | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 75 | |||||||||||||||
| 76 | 3 | ▶ | no Any::Moose '::Exporter'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 77 | |||||||||||||||
| 78 | 3 | 1; | |||||||||||||
| 79 | |||||||||||||||
| 80 | |||||||||||||||
| 81 | __END__ | ||||||||||||||