line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MouseX::NativeTraits; |
2
|
19
|
|
|
19
|
|
14349
|
use 5.006_002; |
|
19
|
|
|
|
|
79
|
|
|
19
|
|
|
|
|
835
|
|
3
|
19
|
|
|
19
|
|
1212
|
use Mouse::Role; |
|
19
|
|
|
|
|
51326
|
|
|
19
|
|
|
|
|
110
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.09'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
requires qw(method_provider_class helper_type); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#has default => ( |
10
|
|
|
|
|
|
|
# is => 'bare', # don't create new methods |
11
|
|
|
|
|
|
|
# required => 1, |
12
|
|
|
|
|
|
|
#); |
13
|
|
|
|
|
|
|
has type_constraint => ( |
14
|
|
|
|
|
|
|
is => 'bare', # don't create new methods |
15
|
|
|
|
|
|
|
required => 1, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has method_provider => ( |
19
|
|
|
|
|
|
|
is => 'ro', |
20
|
|
|
|
|
|
|
isa => 'Object', |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
builder => '_build_method_provider', |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _build_method_provider{ |
26
|
64
|
|
|
64
|
|
5777
|
my($self) = @_; |
27
|
64
|
|
|
|
|
297
|
my $mpc = $self->method_provider_class; |
28
|
64
|
|
|
|
|
253
|
Mouse::Util::load_class($mpc); |
29
|
64
|
|
|
|
|
3005
|
return $mpc->new(attr => $self); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
before _process_options => sub { |
33
|
|
|
|
|
|
|
my ( $self, $name, $options ) = @_; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $type = $self->helper_type; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$options->{isa} = $type |
38
|
|
|
|
|
|
|
if !exists $options->{isa}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $isa = Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint( |
41
|
|
|
|
|
|
|
$options->{isa} ); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
( $isa->is_a_type_of($type) ) |
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
|
|
|
|
|
|
|
if !exists $options->{default} && $self->can('_default_default'); |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
around _canonicalize_handles => sub { |
52
|
|
|
|
|
|
|
my($next, $self) = @_; |
53
|
|
|
|
|
|
|
my $handles_ref = $self->handles; |
54
|
|
|
|
|
|
|
if( ref($handles_ref) ne 'HASH' ) { |
55
|
|
|
|
|
|
|
$self->throw_error( |
56
|
|
|
|
|
|
|
"The 'handles' option must be a HASH reference, not $handles_ref"); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $provider = $self->method_provider; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my %handles; |
62
|
|
|
|
|
|
|
while(my($name, $to) = each %{$handles_ref}){ |
63
|
|
|
|
|
|
|
$to = [$to] if !ref $to; |
64
|
|
|
|
|
|
|
$provider->has_generator($to->[0]) |
65
|
|
|
|
|
|
|
or $self->throw_error("$to->[0] is an unsupported method type"); |
66
|
|
|
|
|
|
|
$handles{$name} = $to; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
return %handles; |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
around _make_delegation_method => sub { |
73
|
|
|
|
|
|
|
my( $next, $self, $handle_name, $method_to_call) = @_; |
74
|
|
|
|
|
|
|
return $self->method_provider->generate($handle_name, $method_to_call); |
75
|
|
|
|
|
|
|
}; |
76
|
|
|
|
|
|
|
|
77
|
19
|
|
|
19
|
|
14408
|
no Mouse::Role; |
|
19
|
|
|
|
|
71
|
|
|
19
|
|
|
|
|
107
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
__END__ |