Filename | /opt/perl-5.18.1/lib/site_perl/5.18.1/Type/Tiny.pm |
Statements | Executed 4002859 statements in 13.0s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1000000 | 1 | 1 | 3.98s | 4.50s | validate | Type::Tiny::
2000039 | 5 | 3 | 1.69s | 1.69s | __ANON__[:32] | Type::Tiny::
1 | 1 | 1 | 2.83ms | 3.01ms | BEGIN@18 | Type::Tiny::
37 | 3 | 2 | 1.22ms | 2.20ms | new | Type::Tiny::
140 | 4 | 1 | 772µs | 973µs | qualified_name | Type::Tiny::
80 | 3 | 2 | 487µs | 1.01ms | __ANON__[:31] | Type::Tiny::
37 | 2 | 1 | 471µs | 3.17ms | _build_compiled_check | Type::Tiny::
12 | 5 | 2 | 329µs | 714µs | inline_check (recurses: max depth 1, inclusive time 209µs) | Type::Tiny::
37 | 2 | 2 | 312µs | 367µs | isa | Type::Tiny::
229 | 4 | 1 | 310µs | 310µs | name | Type::Tiny::
35 | 1 | 1 | 310µs | 344µs | _overload_coderef | Type::Tiny::
201 | 5 | 1 | 276µs | 276µs | CORE:match (opcode) | Type::Tiny::
69 | 5 | 1 | 230µs | 347µs | _is_null_constraint | Type::Tiny::
20 | 2 | 1 | 207µs | 356µs | can_be_inlined | Type::Tiny::
43 | 1 | 1 | 165µs | 317µs | display_name | Type::Tiny::
47 | 2 | 2 | 155µs | 2.80ms | compiled_check (recurses: max depth 1, inclusive time 17µs) | Type::Tiny::
35 | 1 | 1 | 124µs | 173µs | is_anon | Type::Tiny::
37 | 1 | 1 | 113µs | 152µs | _build_display_name | Type::Tiny::
35 | 1 | 1 | 109µs | 157µs | is_parameterizable | Type::Tiny::
69 | 1 | 1 | 106µs | 117µs | constraint | Type::Tiny::
78 | 6 | 1 | 94µs | 94µs | has_parent | Type::Tiny::
1 | 1 | 1 | 82µs | 82µs | BEGIN@24 | Type::Tiny::
35 | 1 | 1 | 48µs | 48µs | has_constraint_generator | Type::Tiny::
1 | 1 | 1 | 41µs | 138µs | BEGIN@31 | Type::Tiny::
35 | 1 | 1 | 34µs | 34µs | message | Type::Tiny::
6 | 2 | 1 | 32µs | 600µs | check | Type::Tiny::
8 | 1 | 1 | 28µs | 39µs | is_parameterized | Type::Tiny::
20 | 1 | 1 | 25µs | 25µs | has_inlined | Type::Tiny::
1 | 1 | 1 | 20µs | 20µs | BEGIN@3 | Type::Tiny::
14 | 3 | 2 | 17µs | 17µs | parent | Type::Tiny::
12 | 1 | 1 | 13µs | 13µs | inlined | Type::Tiny::
1 | 1 | 1 | 12µs | 17µs | BEGIN@5 | Type::Tiny::
8 | 1 | 1 | 12µs | 12µs | has_parameters | Type::Tiny::
13 | 1 | 1 | 11µs | 11µs | _build_constraint | Type::Tiny::
1 | 1 | 1 | 9µs | 53µs | BEGIN@17 | Type::Tiny::
1 | 1 | 1 | 8µs | 23µs | BEGIN@4 | Type::Tiny::
1 | 1 | 1 | 4µs | 4µs | BEGIN@11 | Type::Tiny::
1 | 1 | 1 | 4µs | 4µs | BEGIN@7 | Type::Tiny::
1 | 1 | 1 | 4µs | 4µs | BEGIN@16 | Type::Tiny::
1 | 1 | 1 | 4µs | 4µs | BEGIN@47 | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:142] | Moo::HandleMoose::
0 | 0 | 0 | 0s | 0s | AUTOLOAD | Type::Tiny::
0 | 0 | 0 | 0s | 0s | DESTROY | Type::Tiny::
0 | 0 | 0 | 0s | 0s | DOES | Type::Tiny::
0 | 0 | 0 | 0s | 0s | TIEARRAY | Type::Tiny::
0 | 0 | 0 | 0s | 0s | TIEHASH | Type::Tiny::
0 | 0 | 0 | 0s | 0s | TIESCALAR | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:128] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:257] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:286] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:288] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:297] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:344] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:34] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:35] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:36] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:37] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:38] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:39] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:40] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:41] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:42] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:43] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:44] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:48] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:69] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:766] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:770] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __ANON__[:942] | Type::Tiny::
0 | 0 | 0 | 0s | 0s | __is_parameterized | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _actually_compile_type_constraint | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _add_type_coercions | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _as_string | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _assert_coercion | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _build_coercion | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _build_complementary_type | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _build_default_message | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _build_moose_type | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _build_mouse_type | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _build_name_generator | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _clone | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _compiled_type_coercion | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _compiled_type_constraint | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _croak | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _dd | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _default_message | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _failed_check | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _identity | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _inline_check | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _instantiate_moose_type | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _loose_to_TypeTiny | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _perlcode | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _strict_check | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _swap | Type::Tiny::
0 | 0 | 0 | 0s | 0s | _unite | Type::Tiny::
0 | 0 | 0 | 0s | 0s | assert_coerce | Type::Tiny::
0 | 0 | 0 | 0s | 0s | assert_return | Type::Tiny::
0 | 0 | 0 | 0s | 0s | assert_valid | Type::Tiny::
0 | 0 | 0 | 0s | 0s | can | Type::Tiny::
0 | 0 | 0 | 0s | 0s | child_type_class | Type::Tiny::
0 | 0 | 0 | 0s | 0s | coerce | Type::Tiny::
0 | 0 | 0 | 0s | 0s | coercibles | Type::Tiny::
0 | 0 | 0 | 0s | 0s | coercion | Type::Tiny::
0 | 0 | 0 | 0s | 0s | coercion_generator | Type::Tiny::
0 | 0 | 0 | 0s | 0s | compile_type_constraint | Type::Tiny::
0 | 0 | 0 | 0s | 0s | complementary_type | Type::Tiny::
0 | 0 | 0 | 0s | 0s | constraint_generator | Type::Tiny::
0 | 0 | 0 | 0s | 0s | create_child_type | Type::Tiny::
0 | 0 | 0 | 0s | 0s | deep_explanation | Type::Tiny::
0 | 0 | 0 | 0s | 0s | equals | Type::Tiny::
0 | 0 | 0 | 0s | 0s | get_message | Type::Tiny::
0 | 0 | 0 | 0s | 0s | hand_optimized_type_constraint | Type::Tiny::
0 | 0 | 0 | 0s | 0s | has_coercion | Type::Tiny::
0 | 0 | 0 | 0s | 0s | has_coercion_generator | Type::Tiny::
0 | 0 | 0 | 0s | 0s | has_deep_explanation | Type::Tiny::
0 | 0 | 0 | 0s | 0s | has_hand_optimized_type_constraint | Type::Tiny::
0 | 0 | 0 | 0s | 0s | has_inline_generator | Type::Tiny::
0 | 0 | 0 | 0s | 0s | has_library | Type::Tiny::
0 | 0 | 0 | 0s | 0s | has_message | Type::Tiny::
0 | 0 | 0 | 0s | 0s | inline_assert | Type::Tiny::
0 | 0 | 0 | 0s | 0s | inline_environment | Type::Tiny::
0 | 0 | 0 | 0s | 0s | inline_generator | Type::Tiny::
0 | 0 | 0 | 0s | 0s | is_a_type_of | Type::Tiny::
0 | 0 | 0 | 0s | 0s | is_strictly_a_type_of | Type::Tiny::
0 | 0 | 0 | 0s | 0s | is_strictly_subtype_of | Type::Tiny::
0 | 0 | 0 | 0s | 0s | is_strictly_supertype_of | Type::Tiny::
0 | 0 | 0 | 0s | 0s | is_subtype_of | Type::Tiny::
0 | 0 | 0 | 0s | 0s | is_supertype_of | Type::Tiny::
0 | 0 | 0 | 0s | 0s | library | Type::Tiny::
0 | 0 | 0 | 0s | 0s | meta | Type::Tiny::
0 | 0 | 0 | 0s | 0s | minus_coercions | Type::Tiny::
0 | 0 | 0 | 0s | 0s | moose_type | Type::Tiny::
0 | 0 | 0 | 0s | 0s | mouse_type | Type::Tiny::
0 | 0 | 0 | 0s | 0s | name_generator | Type::Tiny::
0 | 0 | 0 | 0s | 0s | no_coercions | Type::Tiny::
0 | 0 | 0 | 0s | 0s | parameterize | Type::Tiny::
0 | 0 | 0 | 0s | 0s | parameters | Type::Tiny::
0 | 0 | 0 | 0s | 0s | parents | Type::Tiny::
0 | 0 | 0 | 0s | 0s | plus_coercions | Type::Tiny::
0 | 0 | 0 | 0s | 0s | plus_fallback_coercions | Type::Tiny::
0 | 0 | 0 | 0s | 0s | strictly_equals | Type::Tiny::
0 | 0 | 0 | 0s | 0s | type_parameter | Type::Tiny::
0 | 0 | 0 | 0s | 0s | validate_explain | Type::Tiny::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Type::Tiny; | ||||
2 | |||||
3 | 2 | 56µs | 1 | 20µs | # spent 20µs within Type::Tiny::BEGIN@3 which was called:
# once (20µs+0s) by Type::Library::BEGIN@14 at line 3 # spent 20µs making 1 call to Type::Tiny::BEGIN@3 |
4 | 2 | 38µs | 2 | 39µs | # spent 23µs (8+15) within Type::Tiny::BEGIN@4 which was called:
# once (8µs+15µs) by Type::Library::BEGIN@14 at line 4 # spent 23µs making 1 call to Type::Tiny::BEGIN@4
# spent 15µs making 1 call to strict::import |
5 | 2 | 44µs | 2 | 22µs | # spent 17µs (12+5) within Type::Tiny::BEGIN@5 which was called:
# once (12µs+5µs) by Type::Library::BEGIN@14 at line 5 # spent 17µs making 1 call to Type::Tiny::BEGIN@5
# spent 5µs making 1 call to warnings::import |
6 | |||||
7 | # spent 4µs within Type::Tiny::BEGIN@7 which was called:
# once (4µs+0s) by Type::Library::BEGIN@14 at line 9 | ||||
8 | 1 | 12µs | if ($] < 5.008) { require Devel::TypeTiny::Perl56Compat }; | ||
9 | 1 | 43µs | 1 | 4µs | } # spent 4µs making 1 call to Type::Tiny::BEGIN@7 |
10 | |||||
11 | # spent 4µs within Type::Tiny::BEGIN@11 which was called:
# once (4µs+0s) by Type::Library::BEGIN@14 at line 14 | ||||
12 | 1 | 500ns | $Type::Tiny::AUTHORITY = 'cpan:TOBYINK'; | ||
13 | 1 | 5µs | $Type::Tiny::VERSION = '0.038'; | ||
14 | 1 | 22µs | 1 | 4µs | } # spent 4µs making 1 call to Type::Tiny::BEGIN@11 |
15 | |||||
16 | 2 | 30µs | 1 | 4µs | # spent 4µs within Type::Tiny::BEGIN@16 which was called:
# once (4µs+0s) by Type::Library::BEGIN@14 at line 16 # spent 4µs making 1 call to Type::Tiny::BEGIN@16 |
17 | 2 | 31µs | 2 | 97µs | # spent 53µs (9+44) within Type::Tiny::BEGIN@17 which was called:
# once (9µs+44µs) by Type::Library::BEGIN@14 at line 17 # spent 53µs making 1 call to Type::Tiny::BEGIN@17
# spent 44µs making 1 call to Exporter::import |
18 | 2 | 218µs | 1 | 3.01ms | # spent 3.01ms (2.83+177µs) within Type::Tiny::BEGIN@18 which was called:
# once (2.83ms+177µs) by Type::Library::BEGIN@14 at line 18 # spent 3.01ms making 1 call to Type::Tiny::BEGIN@18 |
19 | |||||
20 | sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak } | ||||
21 | |||||
22 | sub _swap { $_[2] ? @_[1,0] : @_[0,1] } | ||||
23 | |||||
24 | # spent 82µs within Type::Tiny::BEGIN@24 which was called:
# once (82µs+0s) by Type::Library::BEGIN@14 at line 28 | ||||
25 | 1 | 84µs | ($] > 5.010001) | ||
26 | ? eval q{ sub SUPPORT_SMARTMATCH () { !!0 } } | ||||
27 | : eval q{ sub SUPPORT_SMARTMATCH () { !!1 } } | ||||
28 | 1 | 559µs | 1 | 82µs | } # spent 82µs making 1 call to Type::Tiny::BEGIN@24 |
29 | |||||
30 | use overload | ||||
31 | 80 | 566µs | 160 | 528µs | # spent 138µs (41+98) within Type::Tiny::BEGIN@31 which was called:
# once (41µs+98µs) by Type::Library::BEGIN@14 at line 46
# spent 1.01ms (487µs+528µs) within Type::Tiny::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Type/Tiny.pm:31] which was called 80 times, avg 13µs/call:
# 37 times (233µs+164µs) by Type::Tiny::new at line 142, avg 11µs/call
# 35 times (202µs+327µs) by Type::Library::_mksub at line 100 of Type/Library.pm, avg 15µs/call
# 8 times (51µs+37µs) by Type::Tiny::_build_compiled_check at line 326, avg 11µs/call # spent 317µs making 43 calls to Type::Tiny::display_name, avg 7µs/call
# spent 109µs making 37 calls to overload::AddrRef, avg 3µs/call
# spent 102µs making 80 calls to Type::Tiny::CORE:match, avg 1µs/call |
32 | 2000039 | 7.04s | # spent 1.69s within Type::Tiny::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Type/Tiny.pm:32] which was called 2000039 times, avg 845ns/call:
# 1000000 times (985ms+0s) by Typed::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Typed.pm:134] at line 118 of Typed.pm, avg 985ns/call
# 1000000 times (706ms+0s) by Typed::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Typed.pm:134] at line 120 of Typed.pm, avg 706ns/call
# 35 times (40µs+0s) by Type::Library::_exporter_expand_sub at line 143 of Type/Library.pm, avg 1µs/call
# 2 times (2µs+0s) by Types::TypeTiny::TypeTiny at line 119 of Types/TypeTiny.pm, avg 1µs/call
# 2 times (2µs+0s) by Types::TypeTiny::StringLike at line 75 of Types/TypeTiny.pm, avg 800ns/call | ||
33 | q(&{}) => "_overload_coderef", | ||||
34 | q(+) => sub { $_[2] ? $_[1]->plus_coercions($_[0]) : $_[0]->plus_fallback_coercions($_[1]) }, | ||||
35 | q(|) => sub { my @tc = _swap @_; require Type::Tiny::Union; "Type::Tiny::Union"->new(type_constraints => \@tc) }, | ||||
36 | q(&) => sub { my @tc = _swap @_; require Type::Tiny::Intersection; "Type::Tiny::Intersection"->new(type_constraints => \@tc) }, | ||||
37 | q(~) => sub { shift->complementary_type }, | ||||
38 | q(==) => sub { $_[0]->equals($_[1]) }, | ||||
39 | q(<) => sub { my $m = $_[0]->can('is_subtype_of'); $m->(_swap @_) }, | ||||
40 | q(>) => sub { my $m = $_[0]->can('is_subtype_of'); $m->(reverse _swap @_) }, | ||||
41 | q(<=) => sub { my $m = $_[0]->can('is_a_type_of'); $m->(_swap @_) }, | ||||
42 | q(>=) => sub { my $m = $_[0]->can('is_a_type_of'); $m->(reverse _swap @_) }, | ||||
43 | q(eq) => sub { "$_[0]" eq "$_[1]" }, | ||||
44 | q(cmp) => sub { $_[2] ? ("$_[1]" cmp "$_[0]") : ("$_[0]" cmp "$_[1]") }, | ||||
45 | 1 | 500ns | fallback => 1, | ||
46 | 1 | 100µs | 2 | 236µs | ; # spent 138µs making 1 call to Type::Tiny::BEGIN@31
# spent 98µs making 1 call to overload::import |
47 | # spent 4µs within Type::Tiny::BEGIN@47 which was called:
# once (4µs+0s) by Type::Library::BEGIN@14 at line 50 | ||||
48 | overload->import(q(~~) => sub { $_[0]->check($_[1]) }) | ||||
49 | 1 | 5µs | if Type::Tiny::SUPPORT_SMARTMATCH; | ||
50 | 1 | 7.22ms | 1 | 4µs | } # spent 4µs making 1 call to Type::Tiny::BEGIN@47 |
51 | |||||
52 | sub _overload_coderef | ||||
53 | # spent 344µs (310+34) within Type::Tiny::_overload_coderef which was called 35 times, avg 10µs/call:
# 35 times (310µs+34µs) by Type::Library::add_type at line 244 of Type/Library.pm, avg 10µs/call | ||||
54 | 35 | 7µs | my $self = shift; | ||
55 | 35 | 44µs | 35 | 34µs | $self->message unless exists $self->{message}; # spent 34µs making 35 calls to Type::Tiny::message, avg 980ns/call |
56 | |||||
57 | # if ($self->has_parent && $self->_is_null_constraint) | ||||
58 | # { | ||||
59 | # $self->{_overload_coderef} ||= $self->parent->_overload_coderef; | ||||
60 | # } | ||||
61 | # els | ||||
62 | 35 | 29µs | if (!exists($self->{message}) && exists(&Sub::Quote::quote_sub) && $self->can_be_inlined) | ||
63 | { | ||||
64 | $self->{_overload_coderef} = Sub::Quote::quote_sub($self->inline_assert('$_[0]')) | ||||
65 | if !$self->{_overload_coderef} || !$self->{_sub_quoted}++; | ||||
66 | } | ||||
67 | else | ||||
68 | { | ||||
69 | 35 | 113µs | $self->{_overload_coderef} ||= sub { $self->assert_return(@_) }; | ||
70 | } | ||||
71 | |||||
72 | 35 | 82µs | $self->{_overload_coderef}; | ||
73 | } | ||||
74 | |||||
75 | 1 | 300ns | our %ALL_TYPES; | ||
76 | |||||
77 | 1 | 100ns | my $QFS; | ||
78 | 1 | 400ns | my $uniq = 1; | ||
79 | sub new | ||||
80 | # spent 2.20ms (1.22+983µs) within Type::Tiny::new which was called 37 times, avg 60µs/call:
# 35 times (1.17ms+953µs) by Type::Library::add_type at line 221 of Type/Library.pm, avg 61µs/call
# once (25µs+15µs) by Types::TypeTiny::TypeTiny at line 119 of Types/TypeTiny.pm
# once (24µs+15µs) by Types::TypeTiny::StringLike at line 75 of Types/TypeTiny.pm | ||||
81 | 37 | 8µs | my $class = shift; | ||
82 | 37 | 115µs | my %params = (@_==1) ? %{$_[0]} : @_; | ||
83 | |||||
84 | 37 | 33µs | if (exists $params{parent}) | ||
85 | { | ||||
86 | 34 | 163µs | 34 | 67µs | $params{parent} = ref($params{parent}) =~ /^Type::Tiny\b/ # spent 67µs making 34 calls to Type::Tiny::CORE:match, avg 2µs/call |
87 | ? $params{parent} | ||||
88 | : Types::TypeTiny::to_TypeTiny($params{parent}); | ||||
89 | |||||
90 | 34 | 158µs | 68 | 382µs | _croak "Parent must be an instance of %s", __PACKAGE__ # spent 338µs making 34 calls to Type::Tiny::isa, avg 10µs/call
# spent 45µs making 34 calls to Scalar::Util::blessed, avg 1µs/call |
91 | unless blessed($params{parent}) && $params{parent}->isa(__PACKAGE__); | ||||
92 | } | ||||
93 | |||||
94 | 37 | 12µs | $params{name} = "__ANON__" unless exists $params{name}; | ||
95 | 37 | 26µs | $params{uniq} = $uniq++; | ||
96 | |||||
97 | 37 | 12µs | if ($params{name} ne "__ANON__") | ||
98 | { | ||||
99 | # First try a fast ASCII-only expression, but fall back to Unicode | ||||
100 | 37 | 157µs | 37 | 81µs | $params{name} =~ /^_{0,2}[A-Z][A-Za-z0-9_]+$/sm # spent 81µs making 37 calls to Type::Tiny::CORE:match, avg 2µs/call |
101 | or eval q( use 5.008; $params{name} =~ /^_{0,2}\p{Lu}[\p{L}0-9_]+$/sm ) | ||||
102 | or _croak '"%s" is not a valid type name', $params{name}; | ||||
103 | } | ||||
104 | |||||
105 | 37 | 11µs | if (exists $params{coercion} and !ref $params{coercion} and $params{coercion}) | ||
106 | { | ||||
107 | $params{parent}->has_coercion | ||||
108 | or _croak "coercion => 1 requires type to have a direct parent with a coercion"; | ||||
109 | |||||
110 | $params{coercion} = $params{parent}->coercion; | ||||
111 | } | ||||
112 | |||||
113 | 37 | 11µs | if (!exists $params{inlined} | ||
114 | and exists $params{constraint} | ||||
115 | and ( !exists $params{parent} or $params{parent}->can_be_inlined ) | ||||
116 | and $QFS ||= "Sub::Quote"->can("quoted_from_sub")) | ||||
117 | { | ||||
118 | my (undef, $perlstring, $captures) = @{ $QFS->($params{constraint}) || [] }; | ||||
119 | |||||
120 | $params{inlined} = sub { | ||||
121 | my ($self, $var) = @_; | ||||
122 | my $code = Sub::Quote::inlinify( | ||||
123 | $var eq q($_) ? $perlstring : "local \$_ = $var; $perlstring", | ||||
124 | $var, | ||||
125 | ); | ||||
126 | $code = sprintf('%s and %s', $self->parent->inline_check($var), $code) if $self->has_parent; | ||||
127 | return $code; | ||||
128 | } if $perlstring && !$captures; | ||||
129 | } | ||||
130 | |||||
131 | 37 | 44µs | my $self = bless \%params, $class; | ||
132 | |||||
133 | 37 | 28µs | unless ($params{tmp}) | ||
134 | { | ||||
135 | 37 | 49µs | my $uniq = $self->{uniq}; | ||
136 | |||||
137 | 37 | 53µs | $ALL_TYPES{$uniq} = $self; | ||
138 | 37 | 141µs | 37 | 55µs | weaken( $ALL_TYPES{$uniq} ); # spent 55µs making 37 calls to Scalar::Util::weaken, avg 1µs/call |
139 | |||||
140 | package # no index | ||||
141 | Moo::HandleMoose; | ||||
142 | 37 | 194µs | 37 | 398µs | $Moo::HandleMoose::TYPE_MAP{$self} = sub { $ALL_TYPES{$uniq} }; # spent 398µs making 37 calls to Type::Tiny::__ANON__[Type/Tiny.pm:31], avg 11µs/call |
143 | } | ||||
144 | |||||
145 | 37 | 28µs | if (ref($params{coercion}) eq q(CODE)) | ||
146 | { | ||||
147 | require Types::Standard; | ||||
148 | my $code = delete($params{coercion}); | ||||
149 | $self->{coercion} = $self->_build_coercion; | ||||
150 | $self->coercion->add_type_coercions(Types::Standard::Any(), $code); | ||||
151 | } | ||||
152 | elsif (ref($params{coercion}) eq q(ARRAY)) | ||||
153 | { | ||||
154 | my $arr = delete($params{coercion}); | ||||
155 | $self->{coercion} = $self->_build_coercion; | ||||
156 | $self->coercion->add_type_coercions(@$arr); | ||||
157 | } | ||||
158 | |||||
159 | 37 | 34µs | $self->{type_constraints} ||= undef; | ||
160 | |||||
161 | 37 | 98µs | return $self; | ||
162 | } | ||||
163 | |||||
164 | sub DESTROY | ||||
165 | { | ||||
166 | my $self = shift; | ||||
167 | delete( $ALL_TYPES{$self->{uniq}} ); | ||||
168 | package # no index | ||||
169 | Moo::HandleMoose; | ||||
170 | delete( $Moo::HandleMoose::TYPE_MAP{$self} ); | ||||
171 | return; | ||||
172 | } | ||||
173 | |||||
174 | sub _clone | ||||
175 | { | ||||
176 | my $self = shift; | ||||
177 | my %opts; | ||||
178 | $opts{$_} = $self->{$_} for qw< name display_name message >; | ||||
179 | $self->create_child_type(%opts); | ||||
180 | } | ||||
181 | |||||
182 | 1 | 0s | our $DD; | ||
183 | sub _dd | ||||
184 | { | ||||
185 | @_ = $_ unless @_; | ||||
186 | my ($value) = @_; | ||||
187 | |||||
188 | goto $DD if ref($DD) eq q(CODE); | ||||
189 | |||||
190 | require B; | ||||
191 | |||||
192 | !defined $value ? 'Undef' : | ||||
193 | !ref $value ? sprintf('Value %s', B::perlstring($value)) : | ||||
194 | do { | ||||
195 | my $N = 0 + (defined($DD) ? $DD : 72); | ||||
196 | require Data::Dumper; | ||||
197 | local $Data::Dumper::Indent = 0; | ||||
198 | local $Data::Dumper::Useqq = 1; | ||||
199 | local $Data::Dumper::Terse = 1; | ||||
200 | local $Data::Dumper::Sortkeys = 1; | ||||
201 | local $Data::Dumper::Maxdepth = 2; | ||||
202 | my $str = Data::Dumper::Dumper($value); | ||||
203 | $str = substr($str, 0, $N - 12).'...'.substr($str, -1, 1) | ||||
204 | if length($str) >= $N; | ||||
205 | "Reference $str"; | ||||
206 | } | ||||
207 | } | ||||
208 | |||||
209 | sub _loose_to_TypeTiny | ||||
210 | { | ||||
211 | map +( | ||||
212 | ref($_) | ||||
213 | ? Types::TypeTiny::to_TypeTiny($_) | ||||
214 | : do { require Type::Utils; Type::Utils::dwim_type($_) } | ||||
215 | ), @_; | ||||
216 | } | ||||
217 | |||||
218 | 229 | 594µs | # spent 310µs within Type::Tiny::name which was called 229 times, avg 1µs/call:
# 140 times (200µs+0s) by Type::Tiny::qualified_name at line 452, avg 1µs/call
# 37 times (40µs+0s) by Type::Tiny::_build_display_name at line 261, avg 1µs/call
# 35 times (49µs+0s) by Type::Tiny::is_anon at line 460, avg 1µs/call
# 17 times (21µs+0s) by Type::Tiny::_build_compiled_check at line 315, avg 1µs/call | ||
219 | 43 | 167µs | 37 | 152µs | # spent 317µs (165+153) within Type::Tiny::display_name which was called 43 times, avg 7µs/call:
# 43 times (165µs+153µs) by Type::Tiny::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Type/Tiny.pm:31] at line 31, avg 7µs/call # spent 152µs making 37 calls to Type::Tiny::_build_display_name, avg 4µs/call |
220 | 14 | 35µs | # spent 17µs within Type::Tiny::parent which was called 14 times, avg 1µs/call:
# 12 times (14µs+0s) by Type::Tiny::_build_compiled_check at line 304, avg 1µs/call
# once (1µs+0s) by Type::Tiny::inline_check at line 610
# once (1µs+0s) by Types::Standard::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Types/Standard.pm:577] at line 575 of Types/Standard.pm | ||
221 | 69 | 164µs | 13 | 11µs | # spent 117µs (106+11) within Type::Tiny::constraint which was called 69 times, avg 2µs/call:
# 69 times (106µs+11µs) by Type::Tiny::_is_null_constraint at line 271, avg 2µs/call # spent 11µs making 13 calls to Type::Tiny::_build_constraint, avg 862ns/call |
222 | 47 | 154µs | 35 | 2.66ms | # spent 2.80ms (155µs+2.64) within Type::Tiny::compiled_check which was called 47 times, avg 60µs/call:
# 35 times (138µs+2.66ms) by Type::Library::add_type at line 242 of Type/Library.pm, avg 80µs/call
# 12 times (17µs+-17µs) by Type::Tiny::_build_compiled_check at line 304, avg 0s/call # spent 2.66ms making 35 calls to Type::Tiny::_build_compiled_check, avg 76µs/call |
223 | sub coercion { $_[0]{coercion} ||= $_[0]->_build_coercion } | ||||
224 | 35 | 85µs | # spent 34µs within Type::Tiny::message which was called 35 times, avg 980ns/call:
# 35 times (34µs+0s) by Type::Tiny::_overload_coderef at line 55, avg 980ns/call | ||
225 | sub library { $_[0]{library} } | ||||
226 | 12 | 25µs | # spent 13µs within Type::Tiny::inlined which was called 12 times, avg 1µs/call:
# 12 times (13µs+0s) by Type::Tiny::inline_check at line 605, avg 1µs/call | ||
227 | sub constraint_generator { $_[0]{constraint_generator} } | ||||
228 | sub inline_generator { $_[0]{inline_generator} } | ||||
229 | sub name_generator { $_[0]{name_generator} ||= $_[0]->_build_name_generator } | ||||
230 | sub coercion_generator { $_[0]{coercion_generator} } | ||||
231 | sub parameters { $_[0]{parameters} } | ||||
232 | sub moose_type { $_[0]{moose_type} ||= $_[0]->_build_moose_type } | ||||
233 | sub mouse_type { $_[0]{mouse_type} ||= $_[0]->_build_mouse_type } | ||||
234 | sub deep_explanation { $_[0]{deep_explanation} } | ||||
235 | |||||
236 | 78 | 177µs | # spent 94µs within Type::Tiny::has_parent which was called 78 times, avg 1µs/call:
# 20 times (24µs+0s) by Type::Tiny::can_be_inlined at line 586, avg 1µs/call
# 20 times (23µs+0s) by Type::Tiny::can_be_inlined at line 588, avg 1µs/call
# 13 times (19µs+0s) by Type::Tiny::_build_compiled_check at line 304, avg 1µs/call
# 12 times (14µs+0s) by Type::Tiny::inline_check at line 599, avg 1µs/call
# 12 times (13µs+0s) by Type::Tiny::inline_check at line 601, avg 1µs/call
# once (2µs+0s) by Type::Tiny::inline_check at line 608 | ||
237 | sub has_library { exists $_[0]{library} } | ||||
238 | sub has_coercion { $_[0]{coercion} and !!@{ $_[0]{coercion}->type_coercion_map } } | ||||
239 | 20 | 44µs | # spent 25µs within Type::Tiny::has_inlined which was called 20 times, avg 1µs/call:
# 20 times (25µs+0s) by Type::Tiny::can_be_inlined at line 590, avg 1µs/call | ||
240 | 35 | 89µs | # spent 48µs within Type::Tiny::has_constraint_generator which was called 35 times, avg 1µs/call:
# 35 times (48µs+0s) by Type::Tiny::is_parameterizable at line 674, avg 1µs/call | ||
241 | sub has_inline_generator { exists $_[0]{inline_generator} } | ||||
242 | sub has_coercion_generator { exists $_[0]{coercion_generator} } | ||||
243 | 8 | 23µs | # spent 12µs within Type::Tiny::has_parameters which was called 8 times, avg 1µs/call:
# 8 times (12µs+0s) by Type::Tiny::is_parameterized at line 679, avg 1µs/call | ||
244 | sub has_message { defined $_[0]{message} } | ||||
245 | sub has_deep_explanation { exists $_[0]{deep_explanation} } | ||||
246 | |||||
247 | sub _default_message { $_[0]{_default_message} ||= $_[0]->_build_default_message } | ||||
248 | |||||
249 | sub _assert_coercion | ||||
250 | { | ||||
251 | my $self = shift; | ||||
252 | _croak "No coercion for this type constraint" | ||||
253 | unless $self->has_coercion && @{$self->coercion->type_coercion_map}; | ||||
254 | return $self->coercion; | ||||
255 | } | ||||
256 | |||||
257 | 1 | 3µs | my $null_constraint = sub { !!1 }; | ||
258 | |||||
259 | sub _build_display_name | ||||
260 | # spent 152µs (113+40) within Type::Tiny::_build_display_name which was called 37 times, avg 4µs/call:
# 37 times (113µs+40µs) by Type::Tiny::display_name at line 219, avg 4µs/call | ||||
261 | 37 | 89µs | 37 | 40µs | shift->name; # spent 40µs making 37 calls to Type::Tiny::name, avg 1µs/call |
262 | } | ||||
263 | |||||
264 | sub _build_constraint | ||||
265 | # spent 11µs within Type::Tiny::_build_constraint which was called 13 times, avg 862ns/call:
# 13 times (11µs+0s) by Type::Tiny::constraint at line 221, avg 862ns/call | ||||
266 | 13 | 32µs | return $null_constraint; | ||
267 | } | ||||
268 | |||||
269 | sub _is_null_constraint | ||||
270 | # spent 347µs (230+117) within Type::Tiny::_is_null_constraint which was called 69 times, avg 5µs/call:
# 37 times (137µs+89µs) by Type::Tiny::_build_compiled_check at line 304, avg 6µs/call
# 16 times (48µs+15µs) by Type::Tiny::can_be_inlined at line 586, avg 4µs/call
# 10 times (28µs+8µs) by Type::Tiny::inline_check at line 599, avg 4µs/call
# 4 times (11µs+4µs) by Type::Tiny::can_be_inlined at line 588, avg 4µs/call
# 2 times (6µs+2µs) by Type::Tiny::inline_check at line 601, avg 4µs/call | ||||
271 | 69 | 205µs | 69 | 117µs | shift->constraint == $null_constraint; # spent 117µs making 69 calls to Type::Tiny::constraint, avg 2µs/call |
272 | } | ||||
273 | |||||
274 | sub _build_coercion | ||||
275 | { | ||||
276 | require Type::Coercion; | ||||
277 | my $self = shift; | ||||
278 | my %opts = (type_constraint => $self); | ||||
279 | $opts{display_name} = "to_$self" unless $self->is_anon; | ||||
280 | return "Type::Coercion"->new(%opts); | ||||
281 | } | ||||
282 | |||||
283 | sub _build_default_message | ||||
284 | { | ||||
285 | my $self = shift; | ||||
286 | return sub { sprintf '%s did not pass type constraint', _dd($_[0]) } if "$self" eq "__ANON__"; | ||||
287 | my $name = "$self"; | ||||
288 | return sub { sprintf '%s did not pass type constraint "%s"', _dd($_[0]), $name }; | ||||
289 | } | ||||
290 | |||||
291 | sub _build_name_generator | ||||
292 | { | ||||
293 | my $self = shift; | ||||
294 | return sub { | ||||
295 | my ($s, @a) = @_; | ||||
296 | sprintf('%s[%s]', $s, join q[,], @a); | ||||
297 | }; | ||||
298 | } | ||||
299 | |||||
300 | sub _build_compiled_check | ||||
301 | { | ||||
302 | 37 | 11µs | my $self = shift; | ||
303 | |||||
304 | 37 | 105µs | 74 | 259µs | if ($self->_is_null_constraint and $self->has_parent) # spent 226µs making 37 calls to Type::Tiny::_is_null_constraint, avg 6µs/call
# spent 19µs making 13 calls to Type::Tiny::has_parent, avg 1µs/call
# spent 14µs making 12 calls to Type::Tiny::parent, avg 1µs/call
# spent 17µs making 12 calls to Type::Tiny::compiled_check, avg 1µs/call, recursion: max depth 1, sum of overlapping time 17µs |
305 | { | ||||
306 | return $self->parent->compiled_check; | ||||
307 | } | ||||
308 | |||||
309 | 25 | 18µs | if ($INC{'Mouse/Util.pm'} and Mouse::Util::MOUSE_XS()) | ||
310 | { | ||||
311 | 25 | 11µs | require Mouse::Util::TypeConstraints; | ||
312 | |||||
313 | 25 | 19µs | 8 | 39µs | if ($self->{_is_core}) # spent 39µs making 8 calls to Type::Tiny::is_parameterized, avg 5µs/call |
314 | { | ||||
315 | 17 | 100µs | 34 | 60µs | my $xs = "Mouse::Util::TypeConstraints"->can($self->name); # spent 38µs making 17 calls to UNIVERSAL::can, avg 2µs/call
# spent 21µs making 17 calls to Type::Tiny::name, avg 1µs/call |
316 | 17 | 44µs | return $xs if $xs; | ||
317 | } | ||||
318 | elsif ($self->is_parameterized and $self->has_parent | ||||
319 | and $self->parent->{_is_core} and $self->parent->name =~ /^(ArrayRef|HashRef|Maybe)$/) | ||||
320 | { | ||||
321 | my $xs = "Mouse::Util::TypeConstraints"->can("_parameterize_".$self->parent->name."_for"); | ||||
322 | return $xs->($self->parameters->[0]) if $xs; | ||||
323 | } | ||||
324 | } | ||||
325 | |||||
326 | 8 | 76µs | 32 | 2.33ms | return Eval::TypeTiny::eval_closure( # spent 1.37ms making 8 calls to Eval::TypeTiny::eval_closure, avg 171µs/call
# spent 714µs making 8 calls to Type::Tiny::inline_check, avg 89µs/call
# spent 155µs making 8 calls to Type::Tiny::can_be_inlined, avg 19µs/call
# spent 88µs making 8 calls to Type::Tiny::__ANON__[Type/Tiny.pm:31], avg 11µs/call |
327 | source => sprintf('sub ($) { %s }', $self->inline_check('$_[0]')), | ||||
328 | description => sprintf("compiled check '%s'", $self), | ||||
329 | ) if $self->can_be_inlined; | ||||
330 | |||||
331 | my @constraints; | ||||
332 | push @constraints, $self->parent->compiled_check if $self->has_parent; | ||||
333 | push @constraints, $self->constraint if !$self->_is_null_constraint; | ||||
334 | return $null_constraint unless @constraints; | ||||
335 | |||||
336 | return sub ($) | ||||
337 | { | ||||
338 | local $_ = $_[0]; | ||||
339 | for my $c (@constraints) | ||||
340 | { | ||||
341 | return unless $c->(@_); | ||||
342 | } | ||||
343 | return !!1; | ||||
344 | }; | ||||
345 | } | ||||
346 | |||||
347 | sub equals | ||||
348 | { | ||||
349 | my ($self, $other) = _loose_to_TypeTiny(@_); | ||||
350 | return unless blessed($self) && $self->isa("Type::Tiny"); | ||||
351 | return unless blessed($other) && $other->isa("Type::Tiny"); | ||||
352 | |||||
353 | return !!1 if refaddr($self) == refaddr($other); | ||||
354 | |||||
355 | return !!1 if $self->has_parent && $self->_is_null_constraint && $self->parent==$other; | ||||
356 | return !!1 if $other->has_parent && $other->_is_null_constraint && $other->parent==$self; | ||||
357 | |||||
358 | return !!1 if refaddr($self->compiled_check) == refaddr($other->compiled_check); | ||||
359 | |||||
360 | return $self->qualified_name eq $other->qualified_name | ||||
361 | if $self->has_library && !$self->is_anon && $other->has_library && !$other->is_anon; | ||||
362 | |||||
363 | return $self->inline_check('$x') eq $other->inline_check('$x') | ||||
364 | if $self->can_be_inlined && $other->can_be_inlined; | ||||
365 | |||||
366 | return; | ||||
367 | } | ||||
368 | |||||
369 | sub is_subtype_of | ||||
370 | { | ||||
371 | my ($self, $other) = _loose_to_TypeTiny(@_); | ||||
372 | return unless blessed($self) && $self->isa("Type::Tiny"); | ||||
373 | return unless blessed($other) && $other->isa("Type::Tiny"); | ||||
374 | |||||
375 | # my $this = $self; | ||||
376 | # while (my $parent = $this->parent) | ||||
377 | # { | ||||
378 | # return !!1 if $parent->equals($other); | ||||
379 | # $this = $parent; | ||||
380 | # } | ||||
381 | # return; | ||||
382 | |||||
383 | return unless $self->has_parent; | ||||
384 | $self->parent->equals($other) or $self->parent->is_subtype_of($other); | ||||
385 | } | ||||
386 | |||||
387 | sub is_supertype_of | ||||
388 | { | ||||
389 | my ($self, $other) = _loose_to_TypeTiny(@_); | ||||
390 | return unless blessed($self) && $self->isa("Type::Tiny"); | ||||
391 | return unless blessed($other) && $other->isa("Type::Tiny"); | ||||
392 | |||||
393 | $other->is_subtype_of($self); | ||||
394 | } | ||||
395 | |||||
396 | sub is_a_type_of | ||||
397 | { | ||||
398 | my ($self, $other) = _loose_to_TypeTiny(@_); | ||||
399 | return unless blessed($self) && $self->isa("Type::Tiny"); | ||||
400 | return unless blessed($other) && $other->isa("Type::Tiny"); | ||||
401 | |||||
402 | $self->equals($other) or $self->is_subtype_of($other); | ||||
403 | } | ||||
404 | |||||
405 | sub strictly_equals | ||||
406 | { | ||||
407 | my ($self, $other) = _loose_to_TypeTiny(@_); | ||||
408 | return unless blessed($self) && $self->isa("Type::Tiny"); | ||||
409 | return unless blessed($other) && $other->isa("Type::Tiny"); | ||||
410 | $self->{uniq} == $other->{uniq}; | ||||
411 | } | ||||
412 | |||||
413 | sub is_strictly_subtype_of | ||||
414 | { | ||||
415 | my ($self, $other) = _loose_to_TypeTiny(@_); | ||||
416 | return unless blessed($self) && $self->isa("Type::Tiny"); | ||||
417 | return unless blessed($other) && $other->isa("Type::Tiny"); | ||||
418 | |||||
419 | # my $this = $self; | ||||
420 | # while (my $parent = $this->parent) | ||||
421 | # { | ||||
422 | # return !!1 if $parent->strictly_equals($other); | ||||
423 | # $this = $parent; | ||||
424 | # } | ||||
425 | # return; | ||||
426 | |||||
427 | return unless $self->has_parent; | ||||
428 | $self->parent->strictly_equals($other) or $self->parent->is_strictly_subtype_of($other); | ||||
429 | } | ||||
430 | |||||
431 | sub is_strictly_supertype_of | ||||
432 | { | ||||
433 | my ($self, $other) = _loose_to_TypeTiny(@_); | ||||
434 | return unless blessed($self) && $self->isa("Type::Tiny"); | ||||
435 | return unless blessed($other) && $other->isa("Type::Tiny"); | ||||
436 | |||||
437 | $other->is_strictly_subtype_of($self); | ||||
438 | } | ||||
439 | |||||
440 | sub is_strictly_a_type_of | ||||
441 | { | ||||
442 | my ($self, $other) = _loose_to_TypeTiny(@_); | ||||
443 | return unless blessed($self) && $self->isa("Type::Tiny"); | ||||
444 | return unless blessed($other) && $other->isa("Type::Tiny"); | ||||
445 | |||||
446 | $self->strictly_equals($other) or $self->is_strictly_subtype_of($other); | ||||
447 | } | ||||
448 | |||||
449 | sub qualified_name | ||||
450 | # spent 973µs (772+200) within Type::Tiny::qualified_name which was called 140 times, avg 7µs/call:
# 35 times (216µs+59µs) by Type::Library::add_type at line 242 of Type/Library.pm, avg 8µs/call
# 35 times (199µs+52µs) by Type::Library::add_type at line 243 of Type/Library.pm, avg 7µs/call
# 35 times (189µs+50µs) by Type::Library::add_type at line 244 of Type/Library.pm, avg 7µs/call
# 35 times (168µs+39µs) by Type::Library::_mksub at line 100 of Type/Library.pm, avg 6µs/call | ||||
451 | 140 | 36µs | my $self = shift; | ||
452 | 140 | 6.43ms | 140 | 200µs | (exists $self->{library} and $self->name ne "__ANON__") # spent 200µs making 140 calls to Type::Tiny::name, avg 1µs/call |
453 | ? "$self->{library}::$self->{name}" | ||||
454 | : $self->{name}; | ||||
455 | } | ||||
456 | |||||
457 | sub is_anon | ||||
458 | # spent 173µs (124+49) within Type::Tiny::is_anon which was called 35 times, avg 5µs/call:
# 35 times (124µs+49µs) by Type::Library::add_type at line 228 of Type/Library.pm, avg 5µs/call | ||||
459 | 35 | 7µs | my $self = shift; | ||
460 | 35 | 101µs | 35 | 49µs | $self->name eq "__ANON__"; # spent 49µs making 35 calls to Type::Tiny::name, avg 1µs/call |
461 | } | ||||
462 | |||||
463 | sub parents | ||||
464 | { | ||||
465 | my $self = shift; | ||||
466 | return unless $self->has_parent; | ||||
467 | return ($self->parent, $self->parent->parents); | ||||
468 | } | ||||
469 | |||||
470 | sub check | ||||
471 | # spent 600µs (32+568) within Type::Tiny::check which was called 6 times, avg 100µs/call:
# 3 times (17µs+309µs) by Type::Coercion::add_type_coercions at line 213 of Type/Coercion.pm, avg 109µs/call
# 3 times (15µs+259µs) by Type::Coercion::add_type_coercions at line 215 of Type/Coercion.pm, avg 91µs/call | ||||
472 | 6 | 1µs | my $self = shift; | ||
473 | 6 | 23µs | 8 | 568µs | ($self->{compiled_type_constraint} ||= $self->_build_compiled_check)->(@_); # spent 512µs making 2 calls to Type::Tiny::_build_compiled_check, avg 256µs/call
# spent 52µs making 3 calls to Eval::TypeTiny::Sandbox::__ANON__[(eval 419)[Eval/TypeTiny.pm:21]:3], avg 17µs/call
# spent 4µs making 3 calls to Eval::TypeTiny::Sandbox::__ANON__[(eval 420)[Eval/TypeTiny.pm:21]:3], avg 1µs/call |
474 | } | ||||
475 | |||||
476 | sub _strict_check | ||||
477 | { | ||||
478 | my $self = shift; | ||||
479 | local $_ = $_[0]; | ||||
480 | |||||
481 | my @constraints = | ||||
482 | reverse | ||||
483 | map { $_->constraint } | ||||
484 | grep { not $_->_is_null_constraint } | ||||
485 | ($self, $self->parents); | ||||
486 | |||||
487 | for my $c (@constraints) | ||||
488 | { | ||||
489 | return unless $c->(@_); | ||||
490 | } | ||||
491 | |||||
492 | return !!1; | ||||
493 | } | ||||
494 | |||||
495 | sub get_message | ||||
496 | { | ||||
497 | my $self = shift; | ||||
498 | local $_ = $_[0]; | ||||
499 | $self->has_message | ||||
500 | ? $self->message->(@_) | ||||
501 | : $self->_default_message->(@_); | ||||
502 | } | ||||
503 | |||||
504 | sub validate | ||||
505 | # spent 4.50s (3.98+519ms) within Type::Tiny::validate which was called 1000000 times, avg 4µs/call:
# 1000000 times (3.98s+519ms) by Typed::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Typed.pm:134] at line 121 of Typed.pm, avg 4µs/call | ||||
506 | 1000000 | 115ms | my $self = shift; | ||
507 | |||||
508 | 1000000 | 5.85s | 1000000 | 519ms | return undef if ($self->{compiled_type_constraint} ||= $self->_build_compiled_check)->(@_); # spent 519ms making 1000000 calls to is_Types::Standard::Int, avg 519ns/call |
509 | |||||
510 | local $_ = $_[0]; | ||||
511 | return $self->get_message(@_); | ||||
512 | } | ||||
513 | |||||
514 | sub validate_explain | ||||
515 | { | ||||
516 | my $self = shift; | ||||
517 | my ($value, $varname) = @_; | ||||
518 | $varname = '$_' unless defined $varname; | ||||
519 | |||||
520 | return undef if $self->check($value); | ||||
521 | |||||
522 | if ($self->has_parent) | ||||
523 | { | ||||
524 | my $parent = $self->parent->validate_explain($value, $varname); | ||||
525 | return [ sprintf('"%s" is a subtype of "%s"', $self, $self->parent), @$parent ] if $parent; | ||||
526 | } | ||||
527 | |||||
528 | my $message = sprintf( | ||||
529 | '%s%s', | ||||
530 | $self->get_message($value), | ||||
531 | $varname eq q{$_} ? '' : sprintf(' (in %s)', $varname), | ||||
532 | ); | ||||
533 | |||||
534 | if ($self->is_parameterized and $self->parent->has_deep_explanation) | ||||
535 | { | ||||
536 | my $deep = $self->parent->deep_explanation->($self, $value, $varname); | ||||
537 | return [ $message, @$deep ] if $deep; | ||||
538 | } | ||||
539 | |||||
540 | return [ $message, sprintf('"%s" is defined as: %s', $self, $self->_perlcode) ]; | ||||
541 | } | ||||
542 | |||||
543 | 1 | 0s | my $b; | ||
544 | sub _perlcode | ||||
545 | { | ||||
546 | my $self = shift; | ||||
547 | |||||
548 | return $self->inline_check('$_') | ||||
549 | if $self->can_be_inlined; | ||||
550 | |||||
551 | $b ||= do { | ||||
552 | require B::Deparse; | ||||
553 | my $tmp = "B::Deparse"->new; | ||||
554 | $tmp->ambient_pragmas(strict => "all", warnings => "all") if $tmp->can('ambient_pragmas'); | ||||
555 | $tmp; | ||||
556 | }; | ||||
557 | |||||
558 | my $code = $b->coderef2text($self->constraint); | ||||
559 | $code =~ s/\s+/ /g; | ||||
560 | return "sub $code"; | ||||
561 | } | ||||
562 | |||||
563 | sub assert_valid | ||||
564 | { | ||||
565 | my $self = shift; | ||||
566 | |||||
567 | return !!1 if ($self->{compiled_type_constraint} ||= $self->_build_compiled_check)->(@_); | ||||
568 | |||||
569 | local $_ = $_[0]; | ||||
570 | $self->_failed_check("$self", $_); | ||||
571 | } | ||||
572 | |||||
573 | sub assert_return | ||||
574 | { | ||||
575 | my $self = shift; | ||||
576 | |||||
577 | return $_[0] if ($self->{compiled_type_constraint} ||= $self->_build_compiled_check)->(@_); | ||||
578 | |||||
579 | local $_ = $_[0]; | ||||
580 | $self->_failed_check("$self", $_); | ||||
581 | } | ||||
582 | |||||
583 | sub can_be_inlined | ||||
584 | { | ||||
585 | 20 | 3µs | my $self = shift; | ||
586 | 20 | 38µs | 36 | 86µs | return $self->parent->can_be_inlined # spent 62µs making 16 calls to Type::Tiny::_is_null_constraint, avg 4µs/call
# spent 24µs making 20 calls to Type::Tiny::has_parent, avg 1µs/call |
587 | if $self->has_parent && $self->_is_null_constraint; | ||||
588 | 20 | 25µs | 24 | 38µs | return !!1 # spent 23µs making 20 calls to Type::Tiny::has_parent, avg 1µs/call
# spent 15µs making 4 calls to Type::Tiny::_is_null_constraint, avg 4µs/call |
589 | if !$self->has_parent && $self->_is_null_constraint; | ||||
590 | 20 | 55µs | 20 | 25µs | return $self->has_inlined; # spent 25µs making 20 calls to Type::Tiny::has_inlined, avg 1µs/call |
591 | } | ||||
592 | |||||
593 | sub inline_check | ||||
594 | # spent 714µs (329+385) within Type::Tiny::inline_check which was called 12 times, avg 60µs/call:
# 8 times (230µs+484µs) by Type::Tiny::_build_compiled_check at line 326, avg 89µs/call
# once (21µs+-21µs) by Type::Tiny::inline_check at line 610
# once (24µs+-24µs) by Types::Standard::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Types/Standard.pm:564] at line 557 of Types/Standard.pm
# once (32µs+-32µs) by Types::Standard::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Types/Standard.pm:159] at line 150 of Types/Standard.pm
# once (22µs+-22µs) by Types::Standard::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Types/Standard.pm:577] at line 575 of Types/Standard.pm | ||||
595 | 12 | 3µs | my $self = shift; | ||
596 | 12 | 12µs | 12 | 200µs | _croak 'Cannot inline type constraint check for "%s"', $self # spent 200µs making 12 calls to Type::Tiny::can_be_inlined, avg 17µs/call |
597 | unless $self->can_be_inlined; | ||||
598 | |||||
599 | 12 | 23µs | 22 | 50µs | return $self->parent->inline_check(@_) # spent 37µs making 10 calls to Type::Tiny::_is_null_constraint, avg 4µs/call
# spent 14µs making 12 calls to Type::Tiny::has_parent, avg 1µs/call |
600 | if $self->has_parent && $self->_is_null_constraint; | ||||
601 | 12 | 13µs | 14 | 20µs | return '(!!1)' # spent 13µs making 12 calls to Type::Tiny::has_parent, avg 1µs/call
# spent 7µs making 2 calls to Type::Tiny::_is_null_constraint, avg 4µs/call |
602 | if !$self->has_parent && $self->_is_null_constraint; | ||||
603 | |||||
604 | 12 | 6µs | local $_ = $_[0]; | ||
605 | 12 | 35µs | 24 | 257µs | my @r = $self->inlined->($self, @_); # spent 82µs making 1 call to Types::Standard::__ANON__[Types/Standard.pm:564]
# spent 73µs making 1 call to Types::Standard::__ANON__[Types/Standard.pm:159]
# spent 63µs making 1 call to Types::Standard::__ANON__[Types/Standard.pm:577]
# spent 13µs making 12 calls to Type::Tiny::inlined, avg 1µs/call
# spent 4µs making 1 call to Types::TypeTiny::__ANON__[Types/TypeTiny.pm:118]
# spent 4µs making 1 call to Types::TypeTiny::__ANON__[Types/TypeTiny.pm:74]
# spent 4µs making 1 call to Types::Standard::__ANON__[Types/Standard.pm:126]
# spent 3µs making 1 call to Types::Standard::__ANON__[Types/Standard.pm:188]
# spent 3µs making 1 call to Types::Standard::__ANON__[Types/Standard.pm:133]
# spent 3µs making 1 call to Types::Standard::__ANON__[Types/Standard.pm:448]
# spent 2µs making 1 call to Types::Standard::__ANON__[Types/Standard.pm:116]
# spent 2µs making 1 call to Types::Standard::__ANON__[Types/Standard.pm:274]
# spent 2µs making 1 call to Types::Standard::__ANON__[Types/Standard.pm:196] |
606 | 12 | 6µs | if (@r and not defined $r[0]) | ||
607 | { | ||||
608 | 1 | 2µs | 1 | 2µs | _croak 'Inlining type constraint check for "%s" returned undef!', $self # spent 2µs making 1 call to Type::Tiny::has_parent |
609 | unless $self->has_parent; | ||||
610 | 1 | 3µs | 2 | 1µs | $r[0] = $self->parent->inline_check(@_); # spent 1µs making 1 call to Type::Tiny::parent
# spent 48µs making 1 call to Type::Tiny::inline_check, recursion: max depth 1, sum of overlapping time 48µs |
611 | } | ||||
612 | 25 | 75µs | 13 | 15µs | my $r = join " && " => map { /[;{}]/ ? "do { $_ }" : "($_)" } @r; # spent 15µs making 13 calls to Type::Tiny::CORE:match, avg 1µs/call |
613 | 12 | 58µs | return @r==1 ? $r : "($r)"; | ||
614 | } | ||||
615 | |||||
616 | sub inline_assert | ||||
617 | { | ||||
618 | require B; | ||||
619 | my $self = shift; | ||||
620 | my $varname = $_[0]; | ||||
621 | my $code = sprintf( | ||||
622 | q[do { no warnings "void"; %s ? %s : Type::Tiny::_failed_check(%d, %s, %s) };], | ||||
623 | $self->inline_check(@_), | ||||
624 | $varname, | ||||
625 | $self->{uniq}, | ||||
626 | B::perlstring("$self"), | ||||
627 | $varname, | ||||
628 | ); | ||||
629 | return $code; | ||||
630 | } | ||||
631 | |||||
632 | sub _failed_check | ||||
633 | { | ||||
634 | require Error::TypeTiny::Assertion; | ||||
635 | |||||
636 | my ($self, $name, $value, %attrs) = @_; | ||||
637 | $self = $ALL_TYPES{$self} unless ref $self; | ||||
638 | |||||
639 | my $exception_class = delete($attrs{exception_class}) || "Error::TypeTiny::Assertion"; | ||||
640 | |||||
641 | if ($self) | ||||
642 | { | ||||
643 | $exception_class->throw( | ||||
644 | message => $self->get_message($value), | ||||
645 | type => $self, | ||||
646 | value => $value, | ||||
647 | %attrs, | ||||
648 | ); | ||||
649 | } | ||||
650 | else | ||||
651 | { | ||||
652 | $exception_class->throw( | ||||
653 | message => sprintf('%s did not pass type constraint "%s"', _dd($value), $name), | ||||
654 | value => $value, | ||||
655 | %attrs, | ||||
656 | ); | ||||
657 | } | ||||
658 | } | ||||
659 | |||||
660 | sub coerce | ||||
661 | { | ||||
662 | my $self = shift; | ||||
663 | $self->_assert_coercion->coerce(@_); | ||||
664 | } | ||||
665 | |||||
666 | sub assert_coerce | ||||
667 | { | ||||
668 | my $self = shift; | ||||
669 | $self->_assert_coercion->assert_coerce(@_); | ||||
670 | } | ||||
671 | |||||
672 | sub is_parameterizable | ||||
673 | # spent 157µs (109+48) within Type::Tiny::is_parameterizable which was called 35 times, avg 4µs/call:
# 35 times (109µs+48µs) by Type::Library::_mksub at line 82 of Type/Library.pm, avg 4µs/call | ||||
674 | 35 | 94µs | 35 | 48µs | shift->has_constraint_generator; # spent 48µs making 35 calls to Type::Tiny::has_constraint_generator, avg 1µs/call |
675 | } | ||||
676 | |||||
677 | sub is_parameterized | ||||
678 | # spent 39µs (28+12) within Type::Tiny::is_parameterized which was called 8 times, avg 5µs/call:
# 8 times (28µs+12µs) by Type::Tiny::_build_compiled_check at line 313, avg 5µs/call | ||||
679 | 8 | 22µs | 8 | 12µs | shift->has_parameters; # spent 12µs making 8 calls to Type::Tiny::has_parameters, avg 1µs/call |
680 | } | ||||
681 | |||||
682 | 1 | 200ns | my %param_cache; | ||
683 | sub parameterize | ||||
684 | { | ||||
685 | my $self = shift; | ||||
686 | |||||
687 | $self->is_parameterizable | ||||
688 | or @_ ? _croak("Type '%s' does not accept parameters", "$self") : return($self); | ||||
689 | |||||
690 | @_ = map Types::TypeTiny::to_TypeTiny($_), @_; | ||||
691 | |||||
692 | # Generate a key for caching parameterized type constraints, | ||||
693 | # but only if all the parameters are strings or type constraints. | ||||
694 | my $key; | ||||
695 | if ( not grep(ref($_) && !Types::TypeTiny::TypeTiny->check($_), @_) ) | ||||
696 | { | ||||
697 | require B; | ||||
698 | $key = join ":", map(Types::TypeTiny::TypeTiny->check($_) ? $_->{uniq} : B::perlstring($_), $self, @_); | ||||
699 | } | ||||
700 | |||||
701 | return $param_cache{$key} if defined $key && defined $param_cache{$key}; | ||||
702 | |||||
703 | local $Type::Tiny::parameterize_type = $self; | ||||
704 | local $_ = $_[0]; | ||||
705 | my $P; | ||||
706 | |||||
707 | my $constraint = $self->constraint_generator->(@_); | ||||
708 | |||||
709 | if (Types::TypeTiny::TypeTiny->check($constraint)) | ||||
710 | { | ||||
711 | $P = $constraint; | ||||
712 | } | ||||
713 | else | ||||
714 | { | ||||
715 | my %options = ( | ||||
716 | constraint => $constraint, | ||||
717 | display_name => $self->name_generator->($self, @_), | ||||
718 | parameters => [@_], | ||||
719 | ); | ||||
720 | $options{inlined} = $self->inline_generator->(@_) | ||||
721 | if $self->has_inline_generator; | ||||
722 | exists $options{$_} && !defined $options{$_} && delete $options{$_} | ||||
723 | for keys %options; | ||||
724 | |||||
725 | $P = $self->create_child_type(%options); | ||||
726 | |||||
727 | my $coercion; | ||||
728 | $coercion = $self->coercion_generator->($self, $P, @_) | ||||
729 | if $self->has_coercion_generator; | ||||
730 | $P->coercion->add_type_coercions( @{$coercion->type_coercion_map} ) | ||||
731 | if $coercion; | ||||
732 | } | ||||
733 | |||||
734 | if (defined $key) | ||||
735 | { | ||||
736 | $param_cache{$key} = $P; | ||||
737 | weaken($param_cache{$key}); | ||||
738 | } | ||||
739 | |||||
740 | return $P; | ||||
741 | } | ||||
742 | |||||
743 | sub child_type_class | ||||
744 | { | ||||
745 | __PACKAGE__; | ||||
746 | } | ||||
747 | |||||
748 | sub create_child_type | ||||
749 | { | ||||
750 | my $self = shift; | ||||
751 | return $self->child_type_class->new(parent => $self, @_); | ||||
752 | } | ||||
753 | |||||
754 | sub complementary_type | ||||
755 | { | ||||
756 | my $self = shift; | ||||
757 | my $r = ($self->{complementary_type} ||= $self->_build_complementary_type); | ||||
758 | weaken($self->{complementary_type}) unless isweak($self->{complementary_type}); | ||||
759 | return $r; | ||||
760 | } | ||||
761 | |||||
762 | sub _build_complementary_type | ||||
763 | { | ||||
764 | my $self = shift; | ||||
765 | my %opts = ( | ||||
766 | constraint => sub { not $self->check($_) }, | ||||
767 | display_name => sprintf("~%s", $self), | ||||
768 | ); | ||||
769 | $opts{display_name} =~ s/^\~{2}//; | ||||
770 | $opts{inlined} = sub { shift; "not(".$self->inline_check(@_).")" } | ||||
771 | if $self->can_be_inlined; | ||||
772 | return "Type::Tiny"->new(%opts); | ||||
773 | } | ||||
774 | |||||
775 | sub _instantiate_moose_type | ||||
776 | { | ||||
777 | my $self = shift; | ||||
778 | my %opts = @_; | ||||
779 | require Moose::Meta::TypeConstraint; | ||||
780 | return "Moose::Meta::TypeConstraint"->new(%opts); | ||||
781 | } | ||||
782 | |||||
783 | sub _build_moose_type | ||||
784 | { | ||||
785 | my $self = shift; | ||||
786 | |||||
787 | my $r; | ||||
788 | if ($self->{_is_core}) | ||||
789 | { | ||||
790 | require Moose::Util::TypeConstraints; | ||||
791 | $r = Moose::Util::TypeConstraints::find_type_constraint($self->name); | ||||
792 | $r->{"Types::TypeTiny::to_TypeTiny"} = $self; | ||||
793 | Scalar::Util::weaken($r->{"Types::TypeTiny::to_TypeTiny"}); | ||||
794 | } | ||||
795 | else | ||||
796 | { | ||||
797 | my %opts; | ||||
798 | $opts{name} = $self->qualified_name if $self->has_library && !$self->is_anon; | ||||
799 | $opts{parent} = $self->parent->moose_type if $self->has_parent; | ||||
800 | $opts{constraint} = $self->constraint unless $self->_is_null_constraint; | ||||
801 | $opts{message} = $self->message if $self->has_message; | ||||
802 | $opts{inlined} = $self->inlined if $self->has_inlined; | ||||
803 | |||||
804 | $r = $self->_instantiate_moose_type(%opts); | ||||
805 | $r->{"Types::TypeTiny::to_TypeTiny"} = $self; | ||||
806 | $self->{moose_type} = $r; # prevent recursion | ||||
807 | $r->coercion($self->coercion->moose_coercion) if $self->has_coercion; | ||||
808 | } | ||||
809 | |||||
810 | return $r; | ||||
811 | } | ||||
812 | |||||
813 | sub _build_mouse_type | ||||
814 | { | ||||
815 | my $self = shift; | ||||
816 | |||||
817 | my %options; | ||||
818 | $options{name} = $self->qualified_name if $self->has_library && !$self->is_anon; | ||||
819 | $options{parent} = $self->parent->mouse_type if $self->has_parent; | ||||
820 | $options{constraint} = $self->constraint unless $self->_is_null_constraint; | ||||
821 | $options{message} = $self->message if $self->has_message; | ||||
822 | |||||
823 | require Mouse::Meta::TypeConstraint; | ||||
824 | my $r = "Mouse::Meta::TypeConstraint"->new(%options); | ||||
825 | |||||
826 | $self->{mouse_type} = $r; # prevent recursion | ||||
827 | $r->_add_type_coercions( | ||||
828 | $self->coercion->freeze->_codelike_type_coercion_map('mouse_type') | ||||
829 | ) if $self->has_coercion; | ||||
830 | |||||
831 | return $r; | ||||
832 | } | ||||
833 | |||||
834 | sub plus_coercions | ||||
835 | { | ||||
836 | my $self = shift; | ||||
837 | |||||
838 | my @more = (@_==1 && blessed($_[0]) && $_[0]->can('type_coercion_map')) | ||||
839 | ? @{ $_[0]->type_coercion_map } | ||||
840 | : (@_==1 && ref $_[0]) ? @{$_[0]} : @_; | ||||
841 | |||||
842 | my $new = $self->_clone; | ||||
843 | $new->coercion->add_type_coercions( | ||||
844 | @more, | ||||
845 | @{$self->coercion->type_coercion_map}, | ||||
846 | ); | ||||
847 | return $new; | ||||
848 | } | ||||
849 | |||||
850 | sub plus_fallback_coercions | ||||
851 | { | ||||
852 | my $self = shift; | ||||
853 | |||||
854 | my @more = (@_==1 && blessed($_[0]) && $_[0]->can('type_coercion_map')) | ||||
855 | ? @{ $_[0]->type_coercion_map } | ||||
856 | : (@_==1 && ref $_[0]) ? @{$_[0]} : @_; | ||||
857 | |||||
858 | my $new = $self->_clone; | ||||
859 | $new->coercion->add_type_coercions( | ||||
860 | @{$self->coercion->type_coercion_map}, | ||||
861 | @more, | ||||
862 | ); | ||||
863 | return $new; | ||||
864 | } | ||||
865 | |||||
866 | sub minus_coercions | ||||
867 | { | ||||
868 | my $self = shift; | ||||
869 | |||||
870 | my @not = (@_==1 && blessed($_[0]) && $_[0]->can('type_coercion_map')) | ||||
871 | ? grep(blessed($_)&&$_->isa("Type::Tiny"), @{ $_[0]->type_coercion_map }) | ||||
872 | : (@_==1 && ref $_[0]) ? @{$_[0]} : @_; | ||||
873 | |||||
874 | my @keep; | ||||
875 | my $c = $self->coercion->type_coercion_map; | ||||
876 | for (my $i = 0; $i <= $#$c; $i += 2) | ||||
877 | { | ||||
878 | my $keep_this = 1; | ||||
879 | NOT: for my $n (@not) | ||||
880 | { | ||||
881 | if ($c->[$i] == $n) | ||||
882 | { | ||||
883 | $keep_this = 0; | ||||
884 | last NOT; | ||||
885 | } | ||||
886 | } | ||||
887 | |||||
888 | push @keep, $c->[$i], $c->[$i+1] if $keep_this; | ||||
889 | } | ||||
890 | |||||
891 | my $new = $self->_clone; | ||||
892 | $new->coercion->add_type_coercions(@keep); | ||||
893 | return $new; | ||||
894 | } | ||||
895 | |||||
896 | sub no_coercions | ||||
897 | { | ||||
898 | shift->_clone; | ||||
899 | } | ||||
900 | |||||
901 | sub coercibles | ||||
902 | { | ||||
903 | my $self = shift; | ||||
904 | $self->has_coercion ? $self->coercion->_source_type_union : $self; | ||||
905 | } | ||||
906 | |||||
907 | sub isa | ||||
908 | # spent 367µs (312+54) within Type::Tiny::isa which was called 37 times, avg 10µs/call:
# 34 times (288µs+50µs) by Type::Tiny::new at line 90, avg 10µs/call
# 3 times (24µs+5µs) by Eval::TypeTiny::Sandbox::__ANON__[(eval 419)[/opt/perl-5.18.1/lib/site_perl/5.18.1/Eval/TypeTiny.pm:21]:3] at line 3 of (eval 419)[Eval/TypeTiny.pm:21], avg 10µs/call | ||||
909 | 37 | 8µs | my $self = shift; | ||
910 | |||||
911 | 37 | 25µs | if ($INC{"Moose.pm"} and ref($self)) | ||
912 | { | ||||
913 | 37 | 10µs | return !!1 if $_[0] eq 'Moose::Meta::TypeConstraint'; | ||
914 | 37 | 4µs | return $self->is_parameterized if $_[0] eq 'Moose::Meta::TypeConstraint::Parameterized'; | ||
915 | 37 | 8µs | return $self->is_parameterizable if $_[0] eq 'Moose::Meta::TypeConstraint::Parameterizable'; | ||
916 | } | ||||
917 | |||||
918 | 37 | 77µs | 37 | 11µs | if ($INC{"Moose.pm"} and ref($self) and $_[0] =~ /^Moose/ and my $r = $self->moose_type->isa(@_)) # spent 11µs making 37 calls to Type::Tiny::CORE:match, avg 292ns/call |
919 | { | ||||
920 | return $r; | ||||
921 | } | ||||
922 | |||||
923 | 37 | 16µs | if ($INC{"Mouse.pm"} and ref($self) and $_[0] eq 'Mouse::Meta::TypeConstraint') | ||
924 | { | ||||
925 | return !!1; | ||||
926 | } | ||||
927 | |||||
928 | 37 | 220µs | 37 | 43µs | $self->SUPER::isa(@_); # spent 43µs making 37 calls to UNIVERSAL::isa, avg 1µs/call |
929 | } | ||||
930 | |||||
931 | sub can | ||||
932 | { | ||||
933 | my $self = shift; | ||||
934 | |||||
935 | return !!0 if $_[0] eq 'type_parameter' && blessed($_[0]) && $_[0]->has_parameters; | ||||
936 | |||||
937 | my $can = $self->SUPER::can(@_); | ||||
938 | return $can if $can; | ||||
939 | |||||
940 | if ($INC{"Moose.pm"} and ref($self) and my $method = $self->moose_type->can(@_)) | ||||
941 | { | ||||
942 | return sub { $method->(shift->moose_type, @_) }; | ||||
943 | } | ||||
944 | |||||
945 | return; | ||||
946 | } | ||||
947 | |||||
948 | sub AUTOLOAD | ||||
949 | { | ||||
950 | my $self = shift; | ||||
951 | my ($m) = (our $AUTOLOAD =~ /::(\w+)$/); | ||||
952 | return if $m eq 'DESTROY'; | ||||
953 | |||||
954 | if ($INC{"Moose.pm"} and ref($self) and my $method = $self->moose_type->can($m)) | ||||
955 | { | ||||
956 | return $method->($self->moose_type, @_); | ||||
957 | } | ||||
958 | |||||
959 | _croak q[Can't locate object method "%s" via package "%s"], $m, ref($self)||$self; | ||||
960 | } | ||||
961 | |||||
962 | sub DOES | ||||
963 | { | ||||
964 | my $self = shift; | ||||
965 | |||||
966 | return !!1 if ref($self) && $_[0] =~ m{^ Type::API::Constraint (?: ::Coercible | ::Inlinable )? $}x; | ||||
967 | return !!1 if !ref($self) && $_[0] eq 'Type::API::Constraint::Constructor'; | ||||
968 | |||||
969 | "UNIVERSAL"->can("DOES") ? $self->SUPER::DOES(@_) : $self->isa(@_); | ||||
970 | } | ||||
971 | |||||
972 | # fill out Moose-compatible API | ||||
973 | sub inline_environment { +{} } | ||||
974 | sub _inline_check { shift->inline_check(@_) } | ||||
975 | sub _compiled_type_constraint { shift->compiled_check(@_) } | ||||
976 | sub meta { _croak("Not really a Moose::Meta::TypeConstraint. Sorry!") } | ||||
977 | sub compile_type_constraint { shift->compiled_check } | ||||
978 | sub _actually_compile_type_constraint { shift->_build_compiled_check } | ||||
979 | sub hand_optimized_type_constraint { shift->{hand_optimized_type_constraint} } | ||||
980 | sub has_hand_optimized_type_constraint { exists(shift->{hand_optimized_type_constraint}) } | ||||
981 | sub type_parameter { (shift->parameters || [])->[0] } | ||||
982 | |||||
983 | # some stuff for Mouse-compatible API | ||||
984 | sub __is_parameterized { shift->is_parameterized(@_) } | ||||
985 | sub _add_type_coercions { shift->coercion->add_type_coercions(@_) }; | ||||
986 | sub _as_string { shift->qualified_name(@_) } | ||||
987 | sub _compiled_type_coercion { shift->coercion->compiled_coercion(@_) }; | ||||
988 | sub _identity { refaddr(shift) }; | ||||
989 | sub _unite { require Type::Tiny::Union; "Type::Tiny::Union"->new(type_constraints => \@_) }; | ||||
990 | |||||
991 | # Hooks for Type::Tie | ||||
992 | sub TIESCALAR { require Type::Tie; unshift @_, 'Type::Tie::SCALAR'; goto \&Type::Tie::SCALAR::TIESCALAR }; | ||||
993 | sub TIEARRAY { require Type::Tie; unshift @_, 'Type::Tie::ARRAY'; goto \&Type::Tie::SCALAR::TIEARRAY }; | ||||
994 | sub TIEHASH { require Type::Tie; unshift @_, 'Type::Tie::HASH'; goto \&Type::Tie::SCALAR::TIEHASH }; | ||||
995 | |||||
996 | 1 | 5µs | 1; | ||
997 | |||||
998 | __END__ | ||||
# spent 276µs within Type::Tiny::CORE:match which was called 201 times, avg 1µs/call:
# 80 times (102µs+0s) by Type::Tiny::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Type/Tiny.pm:31] at line 31, avg 1µs/call
# 37 times (81µs+0s) by Type::Tiny::new at line 100, avg 2µs/call
# 37 times (11µs+0s) by Type::Tiny::isa at line 918, avg 292ns/call
# 34 times (67µs+0s) by Type::Tiny::new at line 86, avg 2µs/call
# 13 times (15µs+0s) by Type::Tiny::inline_check at line 612, avg 1µs/call |