← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Thu Dec 15 15:23:56 2022
Reported on Thu Dec 15 15:27:03 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Tiny/ConstrainedObject.pm
StatementsExecuted 469 statements in 1.01ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
37651146µs146µsType::Tiny::ConstrainedObject::::has_parentType::Tiny::ConstrainedObject::has_parent
112278µs501µsType::Tiny::ConstrainedObject::::newType::Tiny::ConstrainedObject::new
11122µs22µsType::Tiny::ConstrainedObject::::BEGIN@3Type::Tiny::ConstrainedObject::BEGIN@3
1116µs27µsType::Tiny::ConstrainedObject::::BEGIN@5Type::Tiny::ConstrainedObject::BEGIN@5
1115µs7µsType::Tiny::ConstrainedObject::::BEGIN@4Type::Tiny::ConstrainedObject::BEGIN@4
1113µs3µsType::Tiny::ConstrainedObject::::BEGIN@16Type::Tiny::ConstrainedObject::BEGIN@16
1111µs1µ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
3230µs122µs
# spent 22µs within Type::Tiny::ConstrainedObject::BEGIN@3 which was called: # once (22µs+0s) by Type::Tiny::Class::BEGIN@19 at line 3
use 5.008001;
# spent 22µs making 1 call to Type::Tiny::ConstrainedObject::BEGIN@3
4219µs29µs
# spent 7µs (5+2) within Type::Tiny::ConstrainedObject::BEGIN@4 which was called: # once (5µs+2µs) by Type::Tiny::Class::BEGIN@19 at line 4
use strict;
# spent 7µs making 1 call to Type::Tiny::ConstrainedObject::BEGIN@4 # spent 2µs making 1 call to strict::import
5225µs248µs
# spent 27µs (6+21) within Type::Tiny::ConstrainedObject::BEGIN@5 which was called: # once (6µs+21µs) by Type::Tiny::Class::BEGIN@19 at line 5
use warnings;
# spent 27µs making 1 call to Type::Tiny::ConstrainedObject::BEGIN@5 # spent 21µs making 1 call to warnings::import
6
7
# spent 1µs within Type::Tiny::ConstrainedObject::BEGIN@7 which was called: # once (1µs+0s) by Type::Tiny::Class::BEGIN@19 at line 10
BEGIN {
810s $Type::Tiny::ConstrainedObject::AUTHORITY = 'cpan:TOBYINK';
912µs $Type::Tiny::ConstrainedObject::VERSION = '2.000001';
10139µs11µs}
# spent 1µs making 1 call to Type::Tiny::ConstrainedObject::BEGIN@7
11
1211µs$Type::Tiny::ConstrainedObject::VERSION =~ tr/_//d;
13
14sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak }
15
162396µ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
1717µ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 501µs (78+423) within Type::Tiny::ConstrainedObject::new which was called 11 times, avg 46µs/call: # 10 times (68µs+356µs) by Type::Tiny::Class::new at line 57 of Type/Tiny/Class.pm, avg 42µs/call # once (10µs+67µs) by Type::Tiny::Duck::new at line 58 of Type/Tiny/Duck.pm
sub new {
26111µs my $proto = shift;
27119µs my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_;
281112µs for my $key ( qw/ parent constraint inlined / ) {
29339µ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 }
361142µs11423µs $proto->SUPER::new( %opts );
# spent 423µs making 11 calls to Type::Tiny::new, avg 38µs/call
37} #/ sub new
38
39
# spent 146µs within Type::Tiny::ConstrainedObject::has_parent which was called 376 times, avg 388ns/call: # 105 times (69µs+0s) by Type::Tiny::can_be_inlined at line 877 of Type/Tiny.pm, avg 657ns/call # 105 times (31µs+0s) by Type::Tiny::can_be_inlined at line 879 of Type/Tiny.pm, avg 295ns/call # 62 times (14µs+0s) by Type::Tiny::inline_check at line 889 of Type/Tiny.pm, avg 226ns/call # 62 times (13µs+0s) by Type::Tiny::inline_check at line 891 of Type/Tiny.pm, avg 210ns/call # 42 times (19µs+0s) by Type::Tiny::is_strictly_subtype_of at line 697 of Type/Tiny.pm, avg 452ns/call
sub has_parent {
40376408µ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
5210smy $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__