← Index
NYTProf Performance Profile   « line view »
For /usr/local/libexec/sympa/task_manager-debug.pl
  Run on Tue Jun 1 22:32:51 2021
Reported on Tue Jun 1 22:35:04 2021

Filename/usr/local/lib/perl5/site_perl/Specio/Coercion.pm
StatementsExecuted 0 statements in 0s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
0000s0sSpecio::Coercion::::BEGIN@10Specio::Coercion::BEGIN@10
0000s0sSpecio::Coercion::::BEGIN@12Specio::Coercion::BEGIN@12
0000s0sSpecio::Coercion::::BEGIN@3Specio::Coercion::BEGIN@3
0000s0sSpecio::Coercion::::BEGIN@4Specio::Coercion::BEGIN@4
0000s0sSpecio::Coercion::::BEGIN@8Specio::Coercion::BEGIN@8
0000s0sSpecio::Coercion::::BUILDSpecio::Coercion::BUILD
0000s0sSpecio::Coercion::::__ANON__Specio::Coercion::__ANON__ (xsub)
0000s0sSpecio::Coercion::::_attrsSpecio::Coercion::_attrs
0000s0sSpecio::Coercion::::_build_descriptionSpecio::Coercion::_build_description
0000s0sSpecio::Coercion::::_build_optimized_coercionSpecio::Coercion::_build_optimized_coercion
0000s0sSpecio::Coercion::::can_be_inlinedSpecio::Coercion::can_be_inlined
0000s0sSpecio::Coercion::::clone_with_new_toSpecio::Coercion::clone_with_new_to
0000s0sSpecio::Coercion::::coerceSpecio::Coercion::coerce
0000s0sSpecio::Coercion::::inline_coercionSpecio::Coercion::inline_coercion
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Specio::Coercion;
2
3use strict;
4use warnings;
5
6our $VERSION = '0.47';
7
8use Specio::OO;
9
10use Role::Tiny::With;
11
12use Specio::Role::Inlinable;
13with 'Specio::Role::Inlinable';
14
15{
16 ## no critic (Subroutines::ProtectPrivateSubs)
17 my $role_attrs = Specio::Role::Inlinable::_attrs();
18 ## use critic
19
20 my $attrs = {
21 %{$role_attrs},
22 from => {
23 does => 'Specio::Constraint::Role::Interface',
24 required => 1,
25 },
26 to => {
27 does => 'Specio::Constraint::Role::Interface',
28 required => 1,
29 weak_ref => 1,
30 },
31 _coercion => {
32 isa => 'CodeRef',
33 predicate => '_has_coercion',
34 init_arg => 'coercion',
35 },
36 _optimized_coercion => {
37 isa => 'CodeRef',
38 init_arg => undef,
39 lazy => 1,
40 builder => '_build_optimized_coercion',
41 },
42 };
43
44 ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
45 sub _attrs {
46 return $attrs;
47 }
48}
49
50sub BUILD {
51 my $self = shift;
52
53 die
54 'A type coercion should have either a coercion or inline_generator parameter, not both'
55 if $self->_has_coercion && $self->_has_inline_generator;
56
57 die
58 'A type coercion must have either a coercion or inline_generator parameter'
59 unless $self->_has_coercion || $self->_has_inline_generator;
60
61 return;
62}
63
64sub coerce {
65 my $self = shift;
66 my $value = shift;
67
68 return $self->_optimized_coercion->($value);
69}
70
71sub inline_coercion {
72 my $self = shift;
73
74 return $self->_inline_generator->( $self, @_ );
75}
76
77sub _build_optimized_coercion {
78 my $self = shift;
79
80 if ( $self->_has_inline_generator ) {
81 return $self->_generated_inline_sub;
82 }
83 else {
84 return $self->_coercion;
85 }
86}
87
88sub can_be_inlined {
89 my $self = shift;
90
91 return $self->_has_inline_generator && $self->from->can_be_inlined;
92}
93
94sub _build_description {
95 my $self = shift;
96
97 my $from_name
98 = defined $self->from->name ? $self->from->name : 'anonymous type';
99 my $to_name
100 = defined $self->to->name ? $self->to->name : 'anonymous type';
101 my $desc = "coercion from $from_name to $to_name";
102
103 $desc .= q{ } . $self->declared_at->description;
104
105 return $desc;
106}
107
108sub clone_with_new_to {
109 my $self = shift;
110 my $new_to = shift;
111
112 my $from = $self->from;
113
114 local $self->{from} = undef;
115 local $self->{to} = undef;
116
117 my $clone = $self->clone;
118
119 $clone->{from} = $from;
120 $clone->{to} = $new_to;
121
122 return $clone;
123}
124
125__PACKAGE__->_ooify;
126
1271;
128
129# ABSTRACT: A class representing a coercion from one type to another
130
131__END__