← Index
NYTProf Performance Profile   « line view »
For fastest.pl
  Run on Fri Jan 31 20:48:16 2014
Reported on Fri Jan 31 20:49:41 2014

Filename/opt/perl-5.18.1/lib/site_perl/5.18.1/Type/Tiny.pm
StatementsExecuted 4002859 statements in 13.0s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1000000113.98s4.50sType::Tiny::::validate Type::Tiny::validate
2000039531.69s1.69sType::Tiny::::__ANON__[:32] Type::Tiny::__ANON__[:32]
1112.83ms3.01msType::Tiny::::BEGIN@18 Type::Tiny::BEGIN@18
37321.22ms2.20msType::Tiny::::new Type::Tiny::new
14041772µs973µsType::Tiny::::qualified_name Type::Tiny::qualified_name
8032487µs1.01msType::Tiny::::__ANON__[:31] Type::Tiny::__ANON__[:31]
3721471µs3.17msType::Tiny::::_build_compiled_check Type::Tiny::_build_compiled_check
1252329µs714µsType::Tiny::::inline_check Type::Tiny::inline_check (recurses: max depth 1, inclusive time 209µs)
3722312µs367µsType::Tiny::::isa Type::Tiny::isa
22941310µs310µsType::Tiny::::name Type::Tiny::name
3511310µs344µsType::Tiny::::_overload_coderef Type::Tiny::_overload_coderef
20151276µs276µsType::Tiny::::CORE:match Type::Tiny::CORE:match (opcode)
6951230µs347µsType::Tiny::::_is_null_constraint Type::Tiny::_is_null_constraint
2021207µs356µsType::Tiny::::can_be_inlined Type::Tiny::can_be_inlined
4311165µs317µsType::Tiny::::display_name Type::Tiny::display_name
4722155µs2.80msType::Tiny::::compiled_check Type::Tiny::compiled_check (recurses: max depth 1, inclusive time 17µs)
3511124µs173µsType::Tiny::::is_anon Type::Tiny::is_anon
3711113µs152µsType::Tiny::::_build_display_name Type::Tiny::_build_display_name
3511109µs157µsType::Tiny::::is_parameterizable Type::Tiny::is_parameterizable
6911106µs117µsType::Tiny::::constraint Type::Tiny::constraint
786194µs94µsType::Tiny::::has_parent Type::Tiny::has_parent
11182µs82µsType::Tiny::::BEGIN@24 Type::Tiny::BEGIN@24
351148µs48µsType::Tiny::::has_constraint_generator Type::Tiny::has_constraint_generator
11141µs138µsType::Tiny::::BEGIN@31 Type::Tiny::BEGIN@31
351134µs34µsType::Tiny::::message Type::Tiny::message
62132µs600µsType::Tiny::::check Type::Tiny::check
81128µs39µsType::Tiny::::is_parameterized Type::Tiny::is_parameterized
201125µs25µsType::Tiny::::has_inlined Type::Tiny::has_inlined
11120µs20µsType::Tiny::::BEGIN@3 Type::Tiny::BEGIN@3
143217µs17µsType::Tiny::::parent Type::Tiny::parent
121113µs13µsType::Tiny::::inlined Type::Tiny::inlined
11112µs17µsType::Tiny::::BEGIN@5 Type::Tiny::BEGIN@5
81112µs12µsType::Tiny::::has_parameters Type::Tiny::has_parameters
131111µs11µsType::Tiny::::_build_constraint Type::Tiny::_build_constraint
1119µs53µsType::Tiny::::BEGIN@17 Type::Tiny::BEGIN@17
1118µs23µsType::Tiny::::BEGIN@4 Type::Tiny::BEGIN@4
1114µs4µsType::Tiny::::BEGIN@11 Type::Tiny::BEGIN@11
1114µs4µsType::Tiny::::BEGIN@7 Type::Tiny::BEGIN@7
1114µs4µsType::Tiny::::BEGIN@16 Type::Tiny::BEGIN@16
1114µs4µsType::Tiny::::BEGIN@47 Type::Tiny::BEGIN@47
0000s0sMoo::HandleMoose::::__ANON__[:142]Moo::HandleMoose::__ANON__[:142]
0000s0sType::Tiny::::AUTOLOAD Type::Tiny::AUTOLOAD
0000s0sType::Tiny::::DESTROY Type::Tiny::DESTROY
0000s0sType::Tiny::::DOES Type::Tiny::DOES
0000s0sType::Tiny::::TIEARRAY Type::Tiny::TIEARRAY
0000s0sType::Tiny::::TIEHASH Type::Tiny::TIEHASH
0000s0sType::Tiny::::TIESCALAR Type::Tiny::TIESCALAR
0000s0sType::Tiny::::__ANON__[:128] Type::Tiny::__ANON__[:128]
0000s0sType::Tiny::::__ANON__[:257] Type::Tiny::__ANON__[:257]
0000s0sType::Tiny::::__ANON__[:286] Type::Tiny::__ANON__[:286]
0000s0sType::Tiny::::__ANON__[:288] Type::Tiny::__ANON__[:288]
0000s0sType::Tiny::::__ANON__[:297] Type::Tiny::__ANON__[:297]
0000s0sType::Tiny::::__ANON__[:344] Type::Tiny::__ANON__[:344]
0000s0sType::Tiny::::__ANON__[:34] Type::Tiny::__ANON__[:34]
0000s0sType::Tiny::::__ANON__[:35] Type::Tiny::__ANON__[:35]
0000s0sType::Tiny::::__ANON__[:36] Type::Tiny::__ANON__[:36]
0000s0sType::Tiny::::__ANON__[:37] Type::Tiny::__ANON__[:37]
0000s0sType::Tiny::::__ANON__[:38] Type::Tiny::__ANON__[:38]
0000s0sType::Tiny::::__ANON__[:39] Type::Tiny::__ANON__[:39]
0000s0sType::Tiny::::__ANON__[:40] Type::Tiny::__ANON__[:40]
0000s0sType::Tiny::::__ANON__[:41] Type::Tiny::__ANON__[:41]
0000s0sType::Tiny::::__ANON__[:42] Type::Tiny::__ANON__[:42]
0000s0sType::Tiny::::__ANON__[:43] Type::Tiny::__ANON__[:43]
0000s0sType::Tiny::::__ANON__[:44] Type::Tiny::__ANON__[:44]
0000s0sType::Tiny::::__ANON__[:48] Type::Tiny::__ANON__[:48]
0000s0sType::Tiny::::__ANON__[:69] Type::Tiny::__ANON__[:69]
0000s0sType::Tiny::::__ANON__[:766] Type::Tiny::__ANON__[:766]
0000s0sType::Tiny::::__ANON__[:770] Type::Tiny::__ANON__[:770]
0000s0sType::Tiny::::__ANON__[:942] Type::Tiny::__ANON__[:942]
0000s0sType::Tiny::::__is_parameterized Type::Tiny::__is_parameterized
0000s0sType::Tiny::::_actually_compile_type_constraint Type::Tiny::_actually_compile_type_constraint
0000s0sType::Tiny::::_add_type_coercions Type::Tiny::_add_type_coercions
0000s0sType::Tiny::::_as_string Type::Tiny::_as_string
0000s0sType::Tiny::::_assert_coercion Type::Tiny::_assert_coercion
0000s0sType::Tiny::::_build_coercion Type::Tiny::_build_coercion
0000s0sType::Tiny::::_build_complementary_type Type::Tiny::_build_complementary_type
0000s0sType::Tiny::::_build_default_message Type::Tiny::_build_default_message
0000s0sType::Tiny::::_build_moose_type Type::Tiny::_build_moose_type
0000s0sType::Tiny::::_build_mouse_type Type::Tiny::_build_mouse_type
0000s0sType::Tiny::::_build_name_generator Type::Tiny::_build_name_generator
0000s0sType::Tiny::::_clone Type::Tiny::_clone
0000s0sType::Tiny::::_compiled_type_coercion Type::Tiny::_compiled_type_coercion
0000s0sType::Tiny::::_compiled_type_constraint Type::Tiny::_compiled_type_constraint
0000s0sType::Tiny::::_croak Type::Tiny::_croak
0000s0sType::Tiny::::_dd Type::Tiny::_dd
0000s0sType::Tiny::::_default_message Type::Tiny::_default_message
0000s0sType::Tiny::::_failed_check Type::Tiny::_failed_check
0000s0sType::Tiny::::_identity Type::Tiny::_identity
0000s0sType::Tiny::::_inline_check Type::Tiny::_inline_check
0000s0sType::Tiny::::_instantiate_moose_type Type::Tiny::_instantiate_moose_type
0000s0sType::Tiny::::_loose_to_TypeTiny Type::Tiny::_loose_to_TypeTiny
0000s0sType::Tiny::::_perlcode Type::Tiny::_perlcode
0000s0sType::Tiny::::_strict_check Type::Tiny::_strict_check
0000s0sType::Tiny::::_swap Type::Tiny::_swap
0000s0sType::Tiny::::_unite Type::Tiny::_unite
0000s0sType::Tiny::::assert_coerce Type::Tiny::assert_coerce
0000s0sType::Tiny::::assert_return Type::Tiny::assert_return
0000s0sType::Tiny::::assert_valid Type::Tiny::assert_valid
0000s0sType::Tiny::::can Type::Tiny::can
0000s0sType::Tiny::::child_type_class Type::Tiny::child_type_class
0000s0sType::Tiny::::coerce Type::Tiny::coerce
0000s0sType::Tiny::::coercibles Type::Tiny::coercibles
0000s0sType::Tiny::::coercion Type::Tiny::coercion
0000s0sType::Tiny::::coercion_generator Type::Tiny::coercion_generator
0000s0sType::Tiny::::compile_type_constraint Type::Tiny::compile_type_constraint
0000s0sType::Tiny::::complementary_type Type::Tiny::complementary_type
0000s0sType::Tiny::::constraint_generator Type::Tiny::constraint_generator
0000s0sType::Tiny::::create_child_type Type::Tiny::create_child_type
0000s0sType::Tiny::::deep_explanation Type::Tiny::deep_explanation
0000s0sType::Tiny::::equals Type::Tiny::equals
0000s0sType::Tiny::::get_message Type::Tiny::get_message
0000s0sType::Tiny::::hand_optimized_type_constraint Type::Tiny::hand_optimized_type_constraint
0000s0sType::Tiny::::has_coercion Type::Tiny::has_coercion
0000s0sType::Tiny::::has_coercion_generator Type::Tiny::has_coercion_generator
0000s0sType::Tiny::::has_deep_explanation Type::Tiny::has_deep_explanation
0000s0sType::Tiny::::has_hand_optimized_type_constraint Type::Tiny::has_hand_optimized_type_constraint
0000s0sType::Tiny::::has_inline_generator Type::Tiny::has_inline_generator
0000s0sType::Tiny::::has_library Type::Tiny::has_library
0000s0sType::Tiny::::has_message Type::Tiny::has_message
0000s0sType::Tiny::::inline_assert Type::Tiny::inline_assert
0000s0sType::Tiny::::inline_environment Type::Tiny::inline_environment
0000s0sType::Tiny::::inline_generator Type::Tiny::inline_generator
0000s0sType::Tiny::::is_a_type_of Type::Tiny::is_a_type_of
0000s0sType::Tiny::::is_strictly_a_type_of Type::Tiny::is_strictly_a_type_of
0000s0sType::Tiny::::is_strictly_subtype_of Type::Tiny::is_strictly_subtype_of
0000s0sType::Tiny::::is_strictly_supertype_of Type::Tiny::is_strictly_supertype_of
0000s0sType::Tiny::::is_subtype_of Type::Tiny::is_subtype_of
0000s0sType::Tiny::::is_supertype_of Type::Tiny::is_supertype_of
0000s0sType::Tiny::::library Type::Tiny::library
0000s0sType::Tiny::::meta Type::Tiny::meta
0000s0sType::Tiny::::minus_coercions Type::Tiny::minus_coercions
0000s0sType::Tiny::::moose_type Type::Tiny::moose_type
0000s0sType::Tiny::::mouse_type Type::Tiny::mouse_type
0000s0sType::Tiny::::name_generator Type::Tiny::name_generator
0000s0sType::Tiny::::no_coercions Type::Tiny::no_coercions
0000s0sType::Tiny::::parameterize Type::Tiny::parameterize
0000s0sType::Tiny::::parameters Type::Tiny::parameters
0000s0sType::Tiny::::parents Type::Tiny::parents
0000s0sType::Tiny::::plus_coercions Type::Tiny::plus_coercions
0000s0sType::Tiny::::plus_fallback_coercions Type::Tiny::plus_fallback_coercions
0000s0sType::Tiny::::strictly_equals Type::Tiny::strictly_equals
0000s0sType::Tiny::::type_parameter Type::Tiny::type_parameter
0000s0sType::Tiny::::validate_explain Type::Tiny::validate_explain
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Type::Tiny;
2
3256µs120µs
# spent 20µs within Type::Tiny::BEGIN@3 which was called: # once (20µs+0s) by Type::Library::BEGIN@14 at line 3
use 5.006001;
# spent 20µs making 1 call to Type::Tiny::BEGIN@3
4238µs239µ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
use strict;
# spent 23µs making 1 call to Type::Tiny::BEGIN@4 # spent 15µs making 1 call to strict::import
5244µs222µ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
use warnings;
# 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
BEGIN {
8112µs if ($] < 5.008) { require Devel::TypeTiny::Perl56Compat };
9143µs14µ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
BEGIN {
121500ns $Type::Tiny::AUTHORITY = 'cpan:TOBYINK';
1315µs $Type::Tiny::VERSION = '0.038';
14122µs14µs}
# spent 4µs making 1 call to Type::Tiny::BEGIN@11
15
16230µs14µs
# spent 4µs within Type::Tiny::BEGIN@16 which was called: # once (4µs+0s) by Type::Library::BEGIN@14 at line 16
use Eval::TypeTiny ();
# spent 4µs making 1 call to Type::Tiny::BEGIN@16
17231µs297µ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
use Scalar::Util qw( blessed weaken refaddr isweak );
# spent 53µs making 1 call to Type::Tiny::BEGIN@17 # spent 44µs making 1 call to Exporter::import
182218µs13.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
use Types::TypeTiny ();
# spent 3.01ms making 1 call to Type::Tiny::BEGIN@18
19
20sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak }
21
22sub _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
BEGIN {
25184µs ($] > 5.010001)
26 ? eval q{ sub SUPPORT_SMARTMATCH () { !!0 } }
27 : eval q{ sub SUPPORT_SMARTMATCH () { !!1 } }
281559µs182µs}
# spent 82µs making 1 call to Type::Tiny::BEGIN@24
29
30use overload
3180566µs160528µ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
q("") => sub { caller =~ m{^(Moo::HandleMoose|Sub::Quote)} ? overload::StrVal($_[0]) : $_[0]->display_name },
# 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
3220000397.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
q(bool) => sub { 1 },
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]") },
451500ns fallback => 1,
461100µs2236µ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
BEGIN {
48 overload->import(q(~~) => sub { $_[0]->check($_[1]) })
4915µs if Type::Tiny::SUPPORT_SMARTMATCH;
5017.22ms14µs}
# spent 4µs making 1 call to Type::Tiny::BEGIN@47
51
52sub _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
{
54357µs my $self = shift;
553544µs3534µ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
623529µ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 {
6935113µs $self->{_overload_coderef} ||= sub { $self->assert_return(@_) };
70 }
71
723582µs $self->{_overload_coderef};
73}
74
751300nsour %ALL_TYPES;
76
771100nsmy $QFS;
781400nsmy $uniq = 1;
79sub 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
{
81378µs my $class = shift;
8237115µs my %params = (@_==1) ? %{$_[0]} : @_;
83
843733µs if (exists $params{parent})
85 {
8634163µs3467µ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
9034158µs68382µ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
943712µs $params{name} = "__ANON__" unless exists $params{name};
953726µs $params{uniq} = $uniq++;
96
973712µs if ($params{name} ne "__ANON__")
98 {
99 # First try a fast ASCII-only expression, but fall back to Unicode
10037157µs3781µ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
1053711µ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
1133711µ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
1313744µs my $self = bless \%params, $class;
132
1333728µs unless ($params{tmp})
134 {
1353749µs my $uniq = $self->{uniq};
136
1373753µs $ALL_TYPES{$uniq} = $self;
13837141µs3755µ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;
14237194µs37398µ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
1453728µ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
1593734µs $self->{type_constraints} ||= undef;
160
1613798µs return $self;
162}
163
164sub 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
174sub _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
18210sour $DD;
183sub _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
209sub _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
218229594µ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
sub name { $_[0]{name} }
21943167µs37152µ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
sub display_name { $_[0]{display_name} ||= $_[0]->_build_display_name }
# spent 152µs making 37 calls to Type::Tiny::_build_display_name, avg 4µs/call
2201435µ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
sub parent { $_[0]{parent} }
22169164µs1311µ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
sub constraint { $_[0]{constraint} ||= $_[0]->_build_constraint }
# spent 11µs making 13 calls to Type::Tiny::_build_constraint, avg 862ns/call
22247154µs352.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
sub compiled_check { $_[0]{compiled_type_constraint} ||= $_[0]->_build_compiled_check }
# spent 2.66ms making 35 calls to Type::Tiny::_build_compiled_check, avg 76µs/call
223sub coercion { $_[0]{coercion} ||= $_[0]->_build_coercion }
2243585µ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
sub message { $_[0]{message} }
225sub library { $_[0]{library} }
2261225µ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
sub inlined { $_[0]{inlined} }
227sub constraint_generator { $_[0]{constraint_generator} }
228sub inline_generator { $_[0]{inline_generator} }
229sub name_generator { $_[0]{name_generator} ||= $_[0]->_build_name_generator }
230sub coercion_generator { $_[0]{coercion_generator} }
231sub parameters { $_[0]{parameters} }
232sub moose_type { $_[0]{moose_type} ||= $_[0]->_build_moose_type }
233sub mouse_type { $_[0]{mouse_type} ||= $_[0]->_build_mouse_type }
234sub deep_explanation { $_[0]{deep_explanation} }
235
23678177µ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
sub has_parent { exists $_[0]{parent} }
237sub has_library { exists $_[0]{library} }
238sub has_coercion { $_[0]{coercion} and !!@{ $_[0]{coercion}->type_coercion_map } }
2392044µ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
sub has_inlined { exists $_[0]{inlined} }
2403589µ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
sub has_constraint_generator { exists $_[0]{constraint_generator} }
241sub has_inline_generator { exists $_[0]{inline_generator} }
242sub has_coercion_generator { exists $_[0]{coercion_generator} }
243823µ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
sub has_parameters { exists $_[0]{parameters} }
244sub has_message { defined $_[0]{message} }
245sub has_deep_explanation { exists $_[0]{deep_explanation} }
246
247sub _default_message { $_[0]{_default_message} ||= $_[0]->_build_default_message }
248
249sub _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
25713µsmy $null_constraint = sub { !!1 };
258
259sub _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
{
2613789µs3740µs shift->name;
# spent 40µs making 37 calls to Type::Tiny::name, avg 1µs/call
262}
263
264sub _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
{
2661332µs return $null_constraint;
267}
268
269sub _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
{
27169205µs69117µs shift->constraint == $null_constraint;
# spent 117µs making 69 calls to Type::Tiny::constraint, avg 2µs/call
272}
273
274sub _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
283sub _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
291sub _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
300sub _build_compiled_check
301
# spent 3.17ms (471µs+2.70) within Type::Tiny::_build_compiled_check which was called 37 times, avg 86µs/call: # 35 times (433µs+2.23ms) by Type::Tiny::compiled_check at line 222, avg 76µs/call # 2 times (38µs+473µs) by Type::Tiny::check at line 473, avg 256µs/call
{
3023711µs my $self = shift;
303
30437105µs74259µ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
3092518µs if ($INC{'Mouse/Util.pm'} and Mouse::Util::MOUSE_XS())
310 {
3112511µs require Mouse::Util::TypeConstraints;
312
3132519µs839µs if ($self->{_is_core})
# spent 39µs making 8 calls to Type::Tiny::is_parameterized, avg 5µs/call
314 {
31517100µs3460µ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
3161744µ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
326876µs322.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
347sub 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
369sub 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
387sub 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
396sub 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
405sub 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
413sub 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
431sub 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
440sub 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
449sub 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
{
45114036µs my $self = shift;
4521406.43ms140200µ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
457sub 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
{
459357µs my $self = shift;
46035101µs3549µs $self->name eq "__ANON__";
# spent 49µs making 35 calls to Type::Tiny::name, avg 1µs/call
461}
462
463sub parents
464{
465 my $self = shift;
466 return unless $self->has_parent;
467 return ($self->parent, $self->parent->parents);
468}
469
470sub 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
{
47261µs my $self = shift;
473623µs8568µ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
476sub _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
495sub get_message
496{
497 my $self = shift;
498 local $_ = $_[0];
499 $self->has_message
500 ? $self->message->(@_)
501 : $self->_default_message->(@_);
502}
503
504sub 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
{
5061000000115ms my $self = shift;
507
50810000005.85s1000000519ms 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
514sub 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
54310smy $b;
544sub _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
563sub 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
573sub 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
583sub can_be_inlined
584
# spent 356µs (207+149) within Type::Tiny::can_be_inlined which was called 20 times, avg 18µs/call: # 12 times (113µs+87µs) by Type::Tiny::inline_check at line 596, avg 17µs/call # 8 times (94µs+61µs) by Type::Tiny::_build_compiled_check at line 326, avg 19µs/call
{
585203µs my $self = shift;
5862038µs3686µ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;
5882025µs2438µ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;
5902055µs2025µs return $self->has_inlined;
# spent 25µs making 20 calls to Type::Tiny::has_inlined, avg 1µs/call
591}
592
593sub 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
{
595123µs my $self = shift;
5961212µs12200µ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
5991223µs2250µ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;
6011213µs1420µ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
604126µs local $_ = $_[0];
6051235µs24257µ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]
606126µs if (@r and not defined $r[0])
607 {
60812µs12µ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;
61013µs21µ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 }
6122575µs1315µs my $r = join " && " => map { /[;{}]/ ? "do { $_ }" : "($_)" } @r;
# spent 15µs making 13 calls to Type::Tiny::CORE:match, avg 1µs/call
6131258µs return @r==1 ? $r : "($r)";
614}
615
616sub 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
632sub _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
660sub coerce
661{
662 my $self = shift;
663 $self->_assert_coercion->coerce(@_);
664}
665
666sub assert_coerce
667{
668 my $self = shift;
669 $self->_assert_coercion->assert_coerce(@_);
670}
671
672sub 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
{
6743594µs3548µs shift->has_constraint_generator;
# spent 48µs making 35 calls to Type::Tiny::has_constraint_generator, avg 1µs/call
675}
676
677sub 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
{
679822µs812µs shift->has_parameters;
# spent 12µs making 8 calls to Type::Tiny::has_parameters, avg 1µs/call
680}
681
6821200nsmy %param_cache;
683sub 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
743sub child_type_class
744{
745 __PACKAGE__;
746}
747
748sub create_child_type
749{
750 my $self = shift;
751 return $self->child_type_class->new(parent => $self, @_);
752}
753
754sub 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
762sub _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
775sub _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
783sub _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
813sub _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
834sub 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
850sub 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
866sub 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
896sub no_coercions
897{
898 shift->_clone;
899}
900
901sub coercibles
902{
903 my $self = shift;
904 $self->has_coercion ? $self->coercion->_source_type_union : $self;
905}
906
907sub 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
{
909378µs my $self = shift;
910
9113725µs if ($INC{"Moose.pm"} and ref($self))
912 {
9133710µs return !!1 if $_[0] eq 'Moose::Meta::TypeConstraint';
914374µs return $self->is_parameterized if $_[0] eq 'Moose::Meta::TypeConstraint::Parameterized';
915378µs return $self->is_parameterizable if $_[0] eq 'Moose::Meta::TypeConstraint::Parameterizable';
916 }
917
9183777µs3711µ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
9233716µs if ($INC{"Mouse.pm"} and ref($self) and $_[0] eq 'Mouse::Meta::TypeConstraint')
924 {
925 return !!1;
926 }
927
92837220µs3743µs $self->SUPER::isa(@_);
# spent 43µs making 37 calls to UNIVERSAL::isa, avg 1µs/call
929}
930
931sub 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
948sub 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
962sub 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
973sub inline_environment { +{} }
974sub _inline_check { shift->inline_check(@_) }
975sub _compiled_type_constraint { shift->compiled_check(@_) }
976sub meta { _croak("Not really a Moose::Meta::TypeConstraint. Sorry!") }
977sub compile_type_constraint { shift->compiled_check }
978sub _actually_compile_type_constraint { shift->_build_compiled_check }
979sub hand_optimized_type_constraint { shift->{hand_optimized_type_constraint} }
980sub has_hand_optimized_type_constraint { exists(shift->{hand_optimized_type_constraint}) }
981sub type_parameter { (shift->parameters || [])->[0] }
982
983# some stuff for Mouse-compatible API
984sub __is_parameterized { shift->is_parameterized(@_) }
985sub _add_type_coercions { shift->coercion->add_type_coercions(@_) };
986sub _as_string { shift->qualified_name(@_) }
987sub _compiled_type_coercion { shift->coercion->compiled_coercion(@_) };
988sub _identity { refaddr(shift) };
989sub _unite { require Type::Tiny::Union; "Type::Tiny::Union"->new(type_constraints => \@_) };
990
991# Hooks for Type::Tie
992sub TIESCALAR { require Type::Tie; unshift @_, 'Type::Tie::SCALAR'; goto \&Type::Tie::SCALAR::TIESCALAR };
993sub TIEARRAY { require Type::Tie; unshift @_, 'Type::Tie::ARRAY'; goto \&Type::Tie::SCALAR::TIEARRAY };
994sub TIEHASH { require Type::Tie; unshift @_, 'Type::Tie::HASH'; goto \&Type::Tie::SCALAR::TIEHASH };
995
99615µs1;
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
sub Type::Tiny::CORE:match; # opcode