Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Tiny/ConstrainedObject.pm |
Statements | Executed 475 statements in 1.53ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
382 | 5 | 1 | 216µs | 216µs | has_parent | Type::Tiny::ConstrainedObject::
11 | 2 | 2 | 132µs | 675µs | new | Type::Tiny::ConstrainedObject::
1 | 1 | 1 | 36µs | 36µs | BEGIN@3 | Type::Tiny::ConstrainedObject::
1 | 1 | 1 | 7µs | 35µs | BEGIN@5 | Type::Tiny::ConstrainedObject::
1 | 1 | 1 | 6µs | 10µs | BEGIN@4 | Type::Tiny::ConstrainedObject::
1 | 1 | 1 | 3µs | 3µs | BEGIN@16 | Type::Tiny::ConstrainedObject::
1 | 1 | 1 | 2µs | 2µs | BEGIN@7 | Type::Tiny::ConstrainedObject::
0 | 0 | 0 | 0s | 0s | __ANON__[:99] | Type::Tiny::ConstrainedObject::
0 | 0 | 0 | 0s | 0s | _croak | Type::Tiny::ConstrainedObject::
0 | 0 | 0 | 0s | 0s | _short_name | Type::Tiny::ConstrainedObject::
0 | 0 | 0 | 0s | 0s | numifies_to | Type::Tiny::ConstrainedObject::
0 | 0 | 0 | 0s | 0s | parent | Type::Tiny::ConstrainedObject::
0 | 0 | 0 | 0s | 0s | stringifies_to | Type::Tiny::ConstrainedObject::
0 | 0 | 0 | 0s | 0s | with_attribute_values | Type::Tiny::ConstrainedObject::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Type::Tiny::ConstrainedObject; | ||||
2 | |||||
3 | 2 | 42µs | 1 | 36µs | # spent 36µs within Type::Tiny::ConstrainedObject::BEGIN@3 which was called:
# once (36µs+0s) by Type::Tiny::Class::BEGIN@19 at line 3 # spent 36µs making 1 call to Type::Tiny::ConstrainedObject::BEGIN@3 |
4 | 2 | 20µs | 2 | 14µs | # spent 10µs (6+4) within Type::Tiny::ConstrainedObject::BEGIN@4 which was called:
# once (6µs+4µs) by Type::Tiny::Class::BEGIN@19 at line 4 # spent 10µs making 1 call to Type::Tiny::ConstrainedObject::BEGIN@4
# spent 4µs making 1 call to strict::import |
5 | 2 | 33µs | 2 | 63µs | # spent 35µs (7+28) within Type::Tiny::ConstrainedObject::BEGIN@5 which was called:
# once (7µs+28µs) by Type::Tiny::Class::BEGIN@19 at line 5 # spent 35µs making 1 call to Type::Tiny::ConstrainedObject::BEGIN@5
# spent 28µs making 1 call to warnings::import |
6 | |||||
7 | # spent 2µs within Type::Tiny::ConstrainedObject::BEGIN@7 which was called:
# once (2µs+0s) by Type::Tiny::Class::BEGIN@19 at line 10 | ||||
8 | 1 | 0s | $Type::Tiny::ConstrainedObject::AUTHORITY = 'cpan:TOBYINK'; | ||
9 | 1 | 1µs | $Type::Tiny::ConstrainedObject::VERSION = '2.000001'; | ||
10 | 1 | 63µs | 1 | 2µs | } # spent 2µs making 1 call to Type::Tiny::ConstrainedObject::BEGIN@7 |
11 | |||||
12 | 1 | 2µs | $Type::Tiny::ConstrainedObject::VERSION =~ tr/_//d; | ||
13 | |||||
14 | sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak } | ||||
15 | |||||
16 | 2 | 692µs | 1 | 3µs | # spent 3µs within Type::Tiny::ConstrainedObject::BEGIN@16 which was called:
# once (3µs+0s) by Type::Tiny::Class::BEGIN@19 at line 16 # spent 3µs making 1 call to Type::Tiny::ConstrainedObject::BEGIN@16 |
17 | 1 | 10µs | our @ISA = 'Type::Tiny'; | ||
18 | |||||
19 | 1 | 2µs | my %errlabel = ( | ||
20 | parent => 'a parent', | ||||
21 | constraint => 'a constraint coderef', | ||||
22 | inlined => 'an inlining coderef', | ||||
23 | ); | ||||
24 | |||||
25 | # spent 675µs (132+543) within Type::Tiny::ConstrainedObject::new which was called 11 times, avg 61µs/call:
# 10 times (90µs+439µs) by Type::Tiny::Class::new at line 57 of Type/Tiny/Class.pm, avg 53µs/call
# once (42µs+104µs) by Type::Tiny::Duck::new at line 58 of Type/Tiny/Duck.pm | ||||
26 | 11 | 7µs | my $proto = shift; | ||
27 | 11 | 14µs | my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_; | ||
28 | 11 | 45µs | for my $key ( qw/ parent constraint inlined / ) { | ||
29 | 33 | 13µs | next unless exists $opts{$key}; | ||
30 | _croak( | ||||
31 | '%s type constraints cannot have %s passed to the constructor', | ||||
32 | $proto->_short_name, | ||||
33 | $errlabel{$key}, | ||||
34 | ); | ||||
35 | } | ||||
36 | 11 | 57µs | 11 | 543µs | $proto->SUPER::new( %opts ); # spent 543µs making 11 calls to Type::Tiny::new, avg 49µs/call |
37 | } #/ sub new | ||||
38 | |||||
39 | # spent 216µs within Type::Tiny::ConstrainedObject::has_parent which was called 382 times, avg 565ns/call:
# 107 times (104µs+0s) by Type::Tiny::can_be_inlined at line 877 of Type/Tiny.pm, avg 972ns/call
# 107 times (41µs+0s) by Type::Tiny::can_be_inlined at line 879 of Type/Tiny.pm, avg 383ns/call
# 63 times (21µs+0s) by Type::Tiny::inline_check at line 891 of Type/Tiny.pm, avg 333ns/call
# 63 times (21µs+0s) by Type::Tiny::inline_check at line 889 of Type/Tiny.pm, avg 333ns/call
# 42 times (29µs+0s) by Type::Tiny::is_strictly_subtype_of at line 697 of Type/Tiny.pm, avg 690ns/call | ||||
40 | 382 | 518µs | !!1; | ||
41 | } | ||||
42 | |||||
43 | sub parent { | ||||
44 | require Types::Standard; | ||||
45 | Types::Standard::Object(); | ||||
46 | } | ||||
47 | |||||
48 | sub _short_name { | ||||
49 | die "subclasses must implement this"; # uncoverable statement | ||||
50 | } | ||||
51 | |||||
52 | 1 | 1µs | my $i = 0; | ||
53 | my $_where_expressions = sub { | ||||
54 | my $self = shift; | ||||
55 | my $name = shift; | ||||
56 | $name ||= "where expression check"; | ||||
57 | my ( %env, @codes ); | ||||
58 | while ( @_ ) { | ||||
59 | my $expr = shift; | ||||
60 | my $constraint = shift; | ||||
61 | if ( !ref $constraint ) { | ||||
62 | push @codes, sprintf( 'do { local $_ = %s; %s }', $expr, $constraint ); | ||||
63 | } | ||||
64 | else { | ||||
65 | require Types::Standard; | ||||
66 | my $type = | ||||
67 | Types::Standard::is_RegexpRef( $constraint ) | ||||
68 | ? Types::Standard::StrMatch()->of( $constraint ) | ||||
69 | : Types::TypeTiny::to_TypeTiny( $constraint ); | ||||
70 | if ( $type->can_be_inlined ) { | ||||
71 | push @codes, | ||||
72 | sprintf( | ||||
73 | 'do { my $tmp = %s; %s }', $expr, | ||||
74 | $type->inline_check( '$tmp' ) | ||||
75 | ); | ||||
76 | } | ||||
77 | else { | ||||
78 | ++$i; | ||||
79 | $env{ '$chk' . $i } = do { my $chk = $type->compiled_check; \$chk }; | ||||
80 | push @codes, sprintf( '$chk%d->(%s)', $i, $expr ); | ||||
81 | } | ||||
82 | } #/ else [ if ( !ref $constraint )] | ||||
83 | } #/ while ( @_ ) | ||||
84 | |||||
85 | if ( keys %env ) { | ||||
86 | |||||
87 | # cannot inline | ||||
88 | my $sub = Eval::TypeTiny::eval_closure( | ||||
89 | source => | ||||
90 | sprintf( 'sub ($) { local $_ = shift; %s }', join( q( and ), @codes ) ), | ||||
91 | description => sprintf( '%s for %s', $name, $self->name ), | ||||
92 | environment => \%env, | ||||
93 | ); | ||||
94 | return $self->where( $sub ); | ||||
95 | } #/ if ( keys %env ) | ||||
96 | else { | ||||
97 | return $self->where( join( q( and ), @codes ) ); | ||||
98 | } | ||||
99 | 1 | 2µs | }; | ||
100 | |||||
101 | sub stringifies_to { | ||||
102 | my $self = shift; | ||||
103 | my ( $constraint ) = @_; | ||||
104 | $self->$_where_expressions( "stringification check", q{"$_"}, $constraint ); | ||||
105 | } | ||||
106 | |||||
107 | sub numifies_to { | ||||
108 | my $self = shift; | ||||
109 | my ( $constraint ) = @_; | ||||
110 | $self->$_where_expressions( "numification check", q{0+$_}, $constraint ); | ||||
111 | } | ||||
112 | |||||
113 | sub with_attribute_values { | ||||
114 | my $self = shift; | ||||
115 | my %constraint = @_; | ||||
116 | $self->$_where_expressions( | ||||
117 | "attributes check", | ||||
118 | map { my $attr = $_; qq{\$_->$attr} => $constraint{$attr} } | ||||
119 | sort keys %constraint, | ||||
120 | ); | ||||
121 | } | ||||
122 | |||||
123 | 1 | 5µs | 1; | ||
124 | |||||
125 | __END__ |