| Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Tiny/ConstrainedObject.pm |
| Statements | Executed 475 statements in 1.43ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 382 | 5 | 1 | 233µs | 233µs | Type::Tiny::ConstrainedObject::has_parent |
| 11 | 2 | 2 | 87µs | 630µs | Type::Tiny::ConstrainedObject::new |
| 1 | 1 | 1 | 33µs | 33µs | Type::Tiny::ConstrainedObject::BEGIN@3 |
| 1 | 1 | 1 | 8µs | 10µs | Type::Tiny::ConstrainedObject::BEGIN@4 |
| 1 | 1 | 1 | 8µs | 34µs | Type::Tiny::ConstrainedObject::BEGIN@5 |
| 1 | 1 | 1 | 4µs | 4µs | Type::Tiny::ConstrainedObject::BEGIN@16 |
| 1 | 1 | 1 | 3µs | 3µs | Type::Tiny::ConstrainedObject::BEGIN@7 |
| 0 | 0 | 0 | 0s | 0s | Type::Tiny::ConstrainedObject::__ANON__[:99] |
| 0 | 0 | 0 | 0s | 0s | Type::Tiny::ConstrainedObject::_croak |
| 0 | 0 | 0 | 0s | 0s | Type::Tiny::ConstrainedObject::_short_name |
| 0 | 0 | 0 | 0s | 0s | Type::Tiny::ConstrainedObject::numifies_to |
| 0 | 0 | 0 | 0s | 0s | Type::Tiny::ConstrainedObject::parent |
| 0 | 0 | 0 | 0s | 0s | Type::Tiny::ConstrainedObject::stringifies_to |
| 0 | 0 | 0 | 0s | 0s | Type::Tiny::ConstrainedObject::with_attribute_values |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Type::Tiny::ConstrainedObject; | ||||
| 2 | |||||
| 3 | 2 | 46µs | 1 | 33µs | # spent 33µs within Type::Tiny::ConstrainedObject::BEGIN@3 which was called:
# once (33µs+0s) by Type::Tiny::Class::BEGIN@19 at line 3 # spent 33µs making 1 call to Type::Tiny::ConstrainedObject::BEGIN@3 |
| 4 | 2 | 25µs | 2 | 12µs | # spent 10µs (8+2) within Type::Tiny::ConstrainedObject::BEGIN@4 which was called:
# once (8µs+2µs) by Type::Tiny::Class::BEGIN@19 at line 4 # spent 10µs making 1 call to Type::Tiny::ConstrainedObject::BEGIN@4
# spent 2µs making 1 call to strict::import |
| 5 | 2 | 38µs | 2 | 60µs | # spent 34µs (8+26) within Type::Tiny::ConstrainedObject::BEGIN@5 which was called:
# once (8µs+26µs) by Type::Tiny::Class::BEGIN@19 at line 5 # spent 34µs making 1 call to Type::Tiny::ConstrainedObject::BEGIN@5
# spent 26µs making 1 call to warnings::import |
| 6 | |||||
| 7 | # spent 3µs within Type::Tiny::ConstrainedObject::BEGIN@7 which was called:
# once (3µs+0s) by Type::Tiny::Class::BEGIN@19 at line 10 | ||||
| 8 | 1 | 1µs | $Type::Tiny::ConstrainedObject::AUTHORITY = 'cpan:TOBYINK'; | ||
| 9 | 1 | 3µs | $Type::Tiny::ConstrainedObject::VERSION = '2.000001'; | ||
| 10 | 1 | 61µs | 1 | 3µs | } # spent 3µ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 | 535µs | 1 | 4µs | # spent 4µs within Type::Tiny::ConstrainedObject::BEGIN@16 which was called:
# once (4µs+0s) by Type::Tiny::Class::BEGIN@19 at line 16 # spent 4µs making 1 call to Type::Tiny::ConstrainedObject::BEGIN@16 |
| 17 | 1 | 8µ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 630µs (87+543) within Type::Tiny::ConstrainedObject::new which was called 11 times, avg 57µs/call:
# 10 times (77µs+462µs) by Type::Tiny::Class::new at line 57 of Type/Tiny/Class.pm, avg 54µs/call
# once (10µs+81µs) by Type::Tiny::Duck::new at line 58 of Type/Tiny/Duck.pm | ||||
| 26 | 11 | 2µs | my $proto = shift; | ||
| 27 | 11 | 12µ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 | 46µ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 233µs within Type::Tiny::ConstrainedObject::has_parent which was called 382 times, avg 610ns/call:
# 107 times (91µs+0s) by Type::Tiny::can_be_inlined at line 877 of Type/Tiny.pm, avg 850ns/call
# 107 times (46µs+0s) by Type::Tiny::can_be_inlined at line 879 of Type/Tiny.pm, avg 430ns/call
# 63 times (50µs+0s) by Type::Tiny::inline_check at line 889 of Type/Tiny.pm, avg 794ns/call
# 63 times (18µs+0s) by Type::Tiny::inline_check at line 891 of Type/Tiny.pm, avg 286ns/call
# 42 times (28µs+0s) by Type::Tiny::is_strictly_subtype_of at line 697 of Type/Tiny.pm, avg 667ns/call | ||||
| 40 | 382 | 621µ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 | 3µ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 | 6µs | 1; | ||
| 124 | |||||
| 125 | __END__ |