← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Wed Dec 14 15:57:08 2022
Reported on Wed Dec 14 16:00:34 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Tiny/ConstrainedObject.pm
StatementsExecuted 475 statements in 1.53ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
38251216µs216µsType::Tiny::ConstrainedObject::::has_parentType::Tiny::ConstrainedObject::has_parent
1122132µs675µsType::Tiny::ConstrainedObject::::newType::Tiny::ConstrainedObject::new
11136µs36µsType::Tiny::ConstrainedObject::::BEGIN@3Type::Tiny::ConstrainedObject::BEGIN@3
1117µs35µsType::Tiny::ConstrainedObject::::BEGIN@5Type::Tiny::ConstrainedObject::BEGIN@5
1116µs10µsType::Tiny::ConstrainedObject::::BEGIN@4Type::Tiny::ConstrainedObject::BEGIN@4
1113µs3µsType::Tiny::ConstrainedObject::::BEGIN@16Type::Tiny::ConstrainedObject::BEGIN@16
1112µs2µsType::Tiny::ConstrainedObject::::BEGIN@7Type::Tiny::ConstrainedObject::BEGIN@7
0000s0sType::Tiny::ConstrainedObject::::__ANON__[:99]Type::Tiny::ConstrainedObject::__ANON__[:99]
0000s0sType::Tiny::ConstrainedObject::::_croakType::Tiny::ConstrainedObject::_croak
0000s0sType::Tiny::ConstrainedObject::::_short_nameType::Tiny::ConstrainedObject::_short_name
0000s0sType::Tiny::ConstrainedObject::::numifies_toType::Tiny::ConstrainedObject::numifies_to
0000s0sType::Tiny::ConstrainedObject::::parentType::Tiny::ConstrainedObject::parent
0000s0sType::Tiny::ConstrainedObject::::stringifies_toType::Tiny::ConstrainedObject::stringifies_to
0000s0sType::Tiny::ConstrainedObject::::with_attribute_valuesType::Tiny::ConstrainedObject::with_attribute_values
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::ConstrainedObject;
2
3242µs136µ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
use 5.008001;
# spent 36µs making 1 call to Type::Tiny::ConstrainedObject::BEGIN@3
4220µs214µ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
use strict;
# spent 10µs making 1 call to Type::Tiny::ConstrainedObject::BEGIN@4 # spent 4µs making 1 call to strict::import
5233µs263µ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
use warnings;
# 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
BEGIN {
810s $Type::Tiny::ConstrainedObject::AUTHORITY = 'cpan:TOBYINK';
911µs $Type::Tiny::ConstrainedObject::VERSION = '2.000001';
10163µs12µs}
# spent 2µs making 1 call to Type::Tiny::ConstrainedObject::BEGIN@7
11
1212µs$Type::Tiny::ConstrainedObject::VERSION =~ tr/_//d;
13
14sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak }
15
162692µs13µ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
use Type::Tiny ();
# spent 3µs making 1 call to Type::Tiny::ConstrainedObject::BEGIN@16
17110µsour @ISA = 'Type::Tiny';
18
1912µsmy %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
sub new {
26117µs my $proto = shift;
271114µs my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_;
281145µs for my $key ( qw/ parent constraint inlined / ) {
293313µ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 }
361157µs11543µ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
sub has_parent {
40382518µs !!1;
41}
42
43sub parent {
44 require Types::Standard;
45 Types::Standard::Object();
46}
47
48sub _short_name {
49 die "subclasses must implement this"; # uncoverable statement
50}
51
5211µsmy $i = 0;
53my $_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 }
9912µs};
100
101sub stringifies_to {
102 my $self = shift;
103 my ( $constraint ) = @_;
104 $self->$_where_expressions( "stringification check", q{"$_"}, $constraint );
105}
106
107sub numifies_to {
108 my $self = shift;
109 my ( $constraint ) = @_;
110 $self->$_where_expressions( "numification check", q{0+$_}, $constraint );
111}
112
113sub 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
12315µs1;
124
125__END__