« MouseX/NativeTraits/MethodProvider/ArrayRef.pm
↑ Summary
MouseX/NativeTraits/MethodProvider/Counter.pm »
| 1 | package MouseX::NativeTraits; | ||||||||||||||||||||||||||||
| 2 | 19 | ▶ | use 5.006_002; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 19 | ▶ | use Mouse::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 19 | our $VERSION = '1.09'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 19 | requires qw(method_provider_class helper_type); | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | #has default => ( | ||||||||||||||||||||||||||||
| 10 | # is => 'bare', # don't create new methods | ||||||||||||||||||||||||||||
| 11 | # required => 1, | ||||||||||||||||||||||||||||
| 12 | #); | ||||||||||||||||||||||||||||
| 13 | 19 | has type_constraint => ( | |||||||||||||||||||||||||||
| 14 | is => 'bare', # don't create new methods | ||||||||||||||||||||||||||||
| 15 | required => 1, | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 19 | has method_provider => ( | |||||||||||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||||||||||
| 20 | isa => 'Object', | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | builder => '_build_method_provider', | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 64 | ▶ | sub _build_method_provider{ | ||||||||||||||||||||||||||
|
Subroutine
_build_method_provider: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 64 | my($self) = @_; | |||||||||||||||||||||||||||
| 27 | 64 | my $mpc = $self->method_provider_class; | |||||||||||||||||||||||||||
| 28 | 64 | Mouse::Util::load_class($mpc); | |||||||||||||||||||||||||||
| 29 | 64 | return $mpc->new(attr => $self); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 65 | ▶ | before _process_options => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||
| 33 | 65 | my ( $self, $name, $options ) = @_; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 65 | my $type = $self->helper_type; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | $options->{isa} = $type | ||||||||||||||||||||||||||||
| 38 | 65 | ▶ | if !exists $options->{isa}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | my $isa = Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint( | ||||||||||||||||||||||||||||
| 41 | 65 | $options->{isa} ); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 65 | ▶ | ( $isa->is_a_type_of($type) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | || $self->throw_error( | ||||||||||||||||||||||||||||
| 45 | "The type constraint for $name must be a subtype of $type but it's a $isa"); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | $options->{default} = $self->_default_default | ||||||||||||||||||||||||||||
| 48 | 64 | ▶ | if !exists $options->{default} && $self->can('_default_default'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not exists $options->{"default"} and $self->can("_default_default")
MC/DC0%0/2
not exists $options->{"default"} and $self->can("_default_default")
not exists $options->{"default"}
$self->can("_default_default")
Truth table66%2/3
not(A) and B
A= not exists $options->{"default"}B= $self->can("_default_default")
| |||||||||||||||||||||||||||||
| 49 | 19 | }; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 63 | ▶ | around _canonicalize_handles => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 52 | 63 | my($next, $self) = @_; | |||||||||||||||||||||||||||
| 53 | 63 | my $handles_ref = $self->handles; | |||||||||||||||||||||||||||
| 54 | 63 | ▶ | if( ref($handles_ref) ne 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | $self->throw_error( | |||||||||||||||||||||||||||
| 56 | "The 'handles' option must be a HASH reference, not $handles_ref"); | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 63 | my $provider = $self->method_provider; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 63 | my %handles; | |||||||||||||||||||||||||||
| 62 | 63 | ▶ | while(my($name, $to) = each %{$handles_ref}){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 527 | ▶ | $to = [$to] if !ref $to; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 527 | ▶ | $provider->has_generator($to->[0]) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | or $self->throw_error("$to->[0] is an unsupported method type"); | ||||||||||||||||||||||||||||
| 66 | 526 | $handles{$name} = $to; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 62 | return %handles; | |||||||||||||||||||||||||||
| 70 | 19 | }; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 526 | ▶ | around _make_delegation_method => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 73 | 526 | my( $next, $self, $handle_name, $method_to_call) = @_; | |||||||||||||||||||||||||||
| 74 | 526 | return $self->method_provider->generate($handle_name, $method_to_call); | |||||||||||||||||||||||||||
| 75 | 19 | }; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 19 | ▶ | no Mouse::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 78 | 19 | 1; | |||||||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||||||||