| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Type::Tiny::Role; |
|
2
|
|
|
|
|
|
|
|
|
3
|
25
|
|
|
25
|
|
73914
|
use 5.008001; |
|
|
25
|
|
|
|
|
98
|
|
|
4
|
25
|
|
|
25
|
|
161
|
use strict; |
|
|
25
|
|
|
|
|
60
|
|
|
|
25
|
|
|
|
|
910
|
|
|
5
|
25
|
|
|
25
|
|
122
|
use warnings; |
|
|
25
|
|
|
|
|
1307
|
|
|
|
25
|
|
|
|
|
1288
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
|
8
|
25
|
|
|
25
|
|
74
|
$Type::Tiny::Role::AUTHORITY = 'cpan:TOBYINK'; |
|
9
|
25
|
|
|
|
|
1236
|
$Type::Tiny::Role::VERSION = '2.002001'; |
|
10
|
|
|
|
|
|
|
} |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
$Type::Tiny::Role::VERSION =~ tr/_//d; |
|
13
|
|
|
|
|
|
|
|
|
14
|
25
|
|
|
25
|
|
155
|
use Scalar::Util qw< blessed weaken >; |
|
|
25
|
|
|
|
|
52
|
|
|
|
25
|
|
|
|
|
3111
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
5
|
sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak } |
|
|
1
|
|
|
|
|
8
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
25
|
|
|
25
|
|
734
|
use Exporter::Tiny 1.004001 (); |
|
|
25
|
|
|
|
|
5103
|
|
|
|
25
|
|
|
|
|
638
|
|
|
19
|
25
|
|
|
25
|
|
7569
|
use Type::Tiny::ConstrainedObject (); |
|
|
25
|
|
|
|
|
57
|
|
|
|
25
|
|
|
|
|
21788
|
|
|
20
|
|
|
|
|
|
|
our @ISA = qw( Type::Tiny::ConstrainedObject Exporter::Tiny ); |
|
21
|
|
|
|
|
|
|
|
|
22
|
3
|
|
|
3
|
|
10
|
sub _short_name { 'Role' } |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _exporter_fail { |
|
25
|
1
|
|
|
1
|
|
165
|
my ( $class, $name, $opts, $globals ) = @_; |
|
26
|
1
|
|
|
|
|
3
|
my $caller = $globals->{into}; |
|
27
|
|
|
|
|
|
|
|
|
28
|
1
|
50
|
|
|
|
4
|
$opts->{name} = $name unless exists $opts->{name}; $opts->{name} =~ s/:://g; |
|
|
1
|
|
|
|
|
5
|
|
|
29
|
1
|
50
|
|
|
|
6
|
$opts->{role} = $name unless exists $opts->{role}; |
|
30
|
1
|
|
|
|
|
3
|
my $type = $class->new($opts); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$INC{'Type/Registry.pm'} |
|
33
|
|
|
|
|
|
|
? 'Type::Registry'->for_class( $caller )->add_type( $type ) |
|
34
|
|
|
|
|
|
|
: ( $Type::Registry::DELAYED{$caller}{$type->name} = $type ) |
|
35
|
1
|
50
|
33
|
|
|
27
|
unless( ref($caller) or $caller eq '-lexical' or $globals->{'lexical'} ); |
|
|
|
50
|
33
|
|
|
|
|
|
36
|
1
|
|
|
|
|
2
|
return map +( $_->{name} => $_->{code} ), @{ $type->exportables }; |
|
|
1
|
|
|
|
|
4
|
|
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my %cache; |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub new { |
|
42
|
53
|
|
|
53
|
1
|
616
|
my $proto = shift; |
|
43
|
53
|
100
|
|
|
|
263
|
my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_; |
|
|
2
|
|
|
|
|
8
|
|
|
44
|
53
|
100
|
|
|
|
173
|
_croak "Need to supply role name" unless exists $opts{role}; |
|
45
|
52
|
|
|
|
|
294
|
return $proto->SUPER::new( %opts ); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
75
|
|
|
75
|
1
|
202
|
sub role { $_[0]{role} } |
|
49
|
385
|
|
66
|
385
|
1
|
1993
|
sub inlined { $_[0]{inlined} ||= $_[0]->_build_inlined } |
|
50
|
|
|
|
|
|
|
|
|
51
|
750
|
|
|
750
|
1
|
2634
|
sub has_inlined { !!1 } |
|
52
|
|
|
|
|
|
|
|
|
53
|
1343
|
|
|
1343
|
|
3232
|
sub _is_null_constraint { 0 } |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _build_constraint { |
|
56
|
15
|
|
|
15
|
|
28
|
my $self = shift; |
|
57
|
15
|
|
|
|
|
33
|
my $role = $self->role; |
|
58
|
|
|
|
|
|
|
return sub { |
|
59
|
27
|
50
|
|
27
|
|
109
|
blessed( $_ ) and do { |
|
60
|
27
|
|
33
|
|
|
83
|
my $method = $_->can( 'DOES' ) || $_->can( 'isa' ); |
|
61
|
27
|
|
|
|
|
171
|
$_->$method( $role ); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
15
|
|
|
|
|
109
|
}; |
|
64
|
|
|
|
|
|
|
} #/ sub _build_constraint |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _build_inlined { |
|
67
|
49
|
|
|
49
|
|
86
|
my $self = shift; |
|
68
|
49
|
|
|
|
|
106
|
my $role = $self->role; |
|
69
|
|
|
|
|
|
|
sub { |
|
70
|
385
|
|
|
385
|
|
528
|
my $var = $_[1]; |
|
71
|
385
|
|
|
|
|
1319
|
my $code = |
|
72
|
|
|
|
|
|
|
qq{Scalar::Util::blessed($var) and do { my \$method = $var->can('DOES')||$var->can('isa'); $var->\$method(q[$role]) }}; |
|
73
|
385
|
100
|
|
|
|
793
|
return qq{do { use Scalar::Util (); $code }} if $Type::Tiny::AvoidCallbacks; |
|
74
|
340
|
|
|
|
|
809
|
$code; |
|
75
|
49
|
|
|
|
|
331
|
}; |
|
76
|
|
|
|
|
|
|
} #/ sub _build_inlined |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _build_default_message { |
|
79
|
2
|
|
|
2
|
|
4
|
my $self = shift; |
|
80
|
2
|
|
|
|
|
4
|
my $c = $self->role; |
|
81
|
|
|
|
|
|
|
return sub { |
|
82
|
1
|
|
|
1
|
|
5
|
sprintf '%s did not pass type constraint (not DOES %s)', |
|
83
|
|
|
|
|
|
|
Type::Tiny::_dd( $_[0] ), $c; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
2
|
100
|
|
|
|
8
|
if $self->is_anon; |
|
86
|
1
|
|
|
|
|
3
|
my $name = "$self"; |
|
87
|
|
|
|
|
|
|
return sub { |
|
88
|
1
|
|
|
1
|
|
4
|
sprintf '%s did not pass type constraint "%s" (not DOES %s)', |
|
89
|
|
|
|
|
|
|
Type::Tiny::_dd( $_[0] ), $name, $c; |
|
90
|
1
|
|
|
|
|
8
|
}; |
|
91
|
|
|
|
|
|
|
} #/ sub _build_default_message |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub validate_explain { |
|
94
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
|
95
|
2
|
|
|
|
|
4
|
my ( $value, $varname ) = @_; |
|
96
|
2
|
50
|
|
|
|
5
|
$varname = '$_' unless defined $varname; |
|
97
|
|
|
|
|
|
|
|
|
98
|
2
|
50
|
|
|
|
13
|
return undef if $self->check( $value ); |
|
99
|
2
|
50
|
|
|
|
31
|
return ["Not a blessed reference"] unless blessed( $value ); |
|
100
|
2
|
50
|
|
|
|
8
|
return ["Reference provides no DOES method to check roles"] |
|
101
|
|
|
|
|
|
|
unless $value->can( 'DOES' ); |
|
102
|
|
|
|
|
|
|
|
|
103
|
2
|
50
|
|
|
|
8
|
my $display_var = $varname eq q{$_} ? '' : sprintf( ' (in %s)', $varname ); |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
return [ |
|
106
|
2
|
|
|
|
|
7
|
sprintf( '"%s" requires that the reference does %s', $self, $self->role ), |
|
107
|
|
|
|
|
|
|
sprintf( "The reference%s doesn't %s", $display_var, $self->role ), |
|
108
|
|
|
|
|
|
|
]; |
|
109
|
|
|
|
|
|
|
} #/ sub validate_explain |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
__END__ |