Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Tiny/ConstrainedObject.pm |
Statements | Executed 469 statements in 1.10ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
376 | 5 | 1 | 210µs | 210µs | has_parent | Type::Tiny::ConstrainedObject::
11 | 2 | 2 | 98µs | 619µs | new | Type::Tiny::ConstrainedObject::
1 | 1 | 1 | 29µs | 29µs | BEGIN@3 | Type::Tiny::ConstrainedObject::
1 | 1 | 1 | 5µs | 8µs | BEGIN@4 | Type::Tiny::ConstrainedObject::
1 | 1 | 1 | 5µs | 37µs | BEGIN@5 | 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 | 45µs | 1 | 29µs | # spent 29µs within Type::Tiny::ConstrainedObject::BEGIN@3 which was called:
# once (29µs+0s) by Type::Tiny::Class::BEGIN@19 at line 3 # spent 29µs making 1 call to Type::Tiny::ConstrainedObject::BEGIN@3 |
4 | 2 | 24µs | 2 | 11µs | # spent 8µs (5+3) within Type::Tiny::ConstrainedObject::BEGIN@4 which was called:
# once (5µs+3µs) by Type::Tiny::Class::BEGIN@19 at line 4 # spent 8µs making 1 call to Type::Tiny::ConstrainedObject::BEGIN@4
# spent 3µs making 1 call to strict::import |
5 | 2 | 28µs | 2 | 69µs | # spent 37µs (5+32) within Type::Tiny::ConstrainedObject::BEGIN@5 which was called:
# once (5µs+32µs) by Type::Tiny::Class::BEGIN@19 at line 5 # spent 37µs making 1 call to Type::Tiny::ConstrainedObject::BEGIN@5
# spent 32µ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 | 2µs | $Type::Tiny::ConstrainedObject::VERSION = '2.000001'; | ||
10 | 1 | 46µs | 1 | 2µs | } # spent 2µs making 1 call to Type::Tiny::ConstrainedObject::BEGIN@7 |
11 | |||||
12 | 1 | 1µs | $Type::Tiny::ConstrainedObject::VERSION =~ tr/_//d; | ||
13 | |||||
14 | sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak } | ||||
15 | |||||
16 | 2 | 379µ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 | 7µs | our @ISA = 'Type::Tiny'; | ||
18 | |||||
19 | 1 | 1µs | my %errlabel = ( | ||
20 | parent => 'a parent', | ||||
21 | constraint => 'a constraint coderef', | ||||
22 | inlined => 'an inlining coderef', | ||||
23 | ); | ||||
24 | |||||
25 | # spent 619µs (98+521) within Type::Tiny::ConstrainedObject::new which was called 11 times, avg 56µs/call:
# 10 times (90µs+438µs) by Type::Tiny::Class::new at line 57 of Type/Tiny/Class.pm, avg 53µs/call
# once (8µs+83µs) by Type::Tiny::Duck::new at line 58 of Type/Tiny/Duck.pm | ||||
26 | 11 | 6µs | my $proto = shift; | ||
27 | 11 | 11µs | my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_; | ||
28 | 11 | 14µs | for my $key ( qw/ parent constraint inlined / ) { | ||
29 | 33 | 10µ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 | 52µs | 11 | 521µs | $proto->SUPER::new( %opts ); # spent 521µs making 11 calls to Type::Tiny::new, avg 47µs/call |
37 | } #/ sub new | ||||
38 | |||||
39 | # spent 210µs within Type::Tiny::ConstrainedObject::has_parent which was called 376 times, avg 559ns/call:
# 105 times (77µs+0s) by Type::Tiny::can_be_inlined at line 877 of Type/Tiny.pm, avg 733ns/call
# 105 times (28µs+0s) by Type::Tiny::can_be_inlined at line 879 of Type/Tiny.pm, avg 267ns/call
# 62 times (39µs+0s) by Type::Tiny::inline_check at line 889 of Type/Tiny.pm, avg 629ns/call
# 62 times (19µs+0s) by Type::Tiny::inline_check at line 891 of Type/Tiny.pm, avg 306ns/call
# 42 times (47µs+0s) by Type::Tiny::is_strictly_subtype_of at line 697 of Type/Tiny.pm, avg 1µs/call | ||||
40 | 376 | 471µ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 | 0s | 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 | 4µs | 1; | ||
124 | |||||
125 | __END__ |