| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Specio::DeclaredAt; |
|
2
|
|
|
|
|
|
|
|
|
3
|
28
|
|
|
28
|
|
557
|
use strict; |
|
|
28
|
|
|
|
|
49
|
|
|
|
28
|
|
|
|
|
799
|
|
|
4
|
28
|
|
|
28
|
|
127
|
use warnings; |
|
|
28
|
|
|
|
|
48
|
|
|
|
28
|
|
|
|
|
1066
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.46'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
28
|
|
|
28
|
|
156
|
use Specio::OO; |
|
|
28
|
|
|
|
|
50
|
|
|
|
28
|
|
|
|
|
7724
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
{ |
|
11
|
|
|
|
|
|
|
my $attrs = { |
|
12
|
|
|
|
|
|
|
package => { |
|
13
|
|
|
|
|
|
|
isa => 'Str', |
|
14
|
|
|
|
|
|
|
required => 1, |
|
15
|
|
|
|
|
|
|
}, |
|
16
|
|
|
|
|
|
|
filename => { |
|
17
|
|
|
|
|
|
|
isa => 'Str', |
|
18
|
|
|
|
|
|
|
required => 1, |
|
19
|
|
|
|
|
|
|
}, |
|
20
|
|
|
|
|
|
|
line => { |
|
21
|
|
|
|
|
|
|
isa => 'Int', |
|
22
|
|
|
|
|
|
|
required => 1, |
|
23
|
|
|
|
|
|
|
}, |
|
24
|
|
|
|
|
|
|
subroutine => { |
|
25
|
|
|
|
|
|
|
isa => 'Str', |
|
26
|
|
|
|
|
|
|
predicate => 'has_subroutine', |
|
27
|
|
|
|
|
|
|
}, |
|
28
|
|
|
|
|
|
|
}; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) |
|
31
|
|
|
|
|
|
|
sub _attrs { |
|
32
|
8665
|
|
|
8665
|
|
12580
|
return $attrs; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub new_from_caller { |
|
37
|
887
|
|
|
887
|
1
|
1294
|
my $class = shift; |
|
38
|
887
|
|
|
|
|
1120
|
my $depth = shift; |
|
39
|
|
|
|
|
|
|
|
|
40
|
887
|
|
|
|
|
1068
|
my %p; |
|
41
|
887
|
|
|
|
|
6429
|
@p{qw( package filename line )} = ( caller($depth) )[ 0, 1, 2 ]; |
|
42
|
|
|
|
|
|
|
|
|
43
|
887
|
|
|
|
|
3759
|
my $sub = ( caller( $depth + 1 ) )[3]; |
|
44
|
887
|
100
|
|
|
|
2534
|
$p{subroutine} = $sub if defined $sub; |
|
45
|
|
|
|
|
|
|
|
|
46
|
887
|
|
|
|
|
2916
|
return $class->new(%p); |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub description { |
|
50
|
866
|
|
|
866
|
1
|
2921
|
my $self = shift; |
|
51
|
|
|
|
|
|
|
|
|
52
|
866
|
|
|
|
|
1874
|
my $package = $self->package; |
|
53
|
866
|
|
|
|
|
3033
|
my $filename = $self->filename; |
|
54
|
866
|
|
|
|
|
2806
|
my $line = $self->line; |
|
55
|
|
|
|
|
|
|
|
|
56
|
866
|
|
|
|
|
2923
|
my $desc = "declared in package $package ($filename) at line $line"; |
|
57
|
866
|
100
|
|
|
|
1850
|
if ( $self->has_subroutine ) { |
|
58
|
816
|
|
|
|
|
3322
|
$desc .= ' in sub named ' . $self->subroutine; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
866
|
|
|
|
|
4668
|
return $desc; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__PACKAGE__->_ooify; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# ABSTRACT: A class to represent where a type or coercion was declared |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=pod |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=encoding UTF-8 |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 NAME |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Specio::DeclaredAt - A class to represent where a type or coercion was declared |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 VERSION |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
version 0.46 |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $declared = Specio::DeclaredAt->new_from_caller(1); |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
print $declared->description; |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
This class provides a thin wrapper around some of the return values from |
|
93
|
|
|
|
|
|
|
Perl's C<caller> built-in. It's used internally to identify where types and |
|
94
|
|
|
|
|
|
|
coercions are being declared, which is useful when generating error messages. |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 API |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This class provides the following methods. |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 Specio::DeclaredAt->new_from_caller($depth) |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Given a call stack depth, this method returns a new C<Specio::DeclaredAt> |
|
103
|
|
|
|
|
|
|
object. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 $declared_at->package, $declared_at->filename, $declared_at->line |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Returns the call stack information recorded when the object was created. These |
|
108
|
|
|
|
|
|
|
values are always populated. |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 $declared_at->subroutine |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Returns the subroutine from the call stack. This may be an C<udnef> |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 $declared_at->has_subroutine |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Returns true if there is a subroutine name associated with this object. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 $declared_at->description |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Puts all the information together into a single string like "declared in |
|
121
|
|
|
|
|
|
|
package Foo::Bar (.../Foo/Bar.pm) at line 42 in sub named blah". |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 SUPPORT |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Bugs may be submitted at L<https://github.com/houseabsolute/Specio/issues>. |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 SOURCE |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
The source code repository for Specio can be found at L<https://github.com/houseabsolute/Specio>. |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 AUTHOR |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This software is Copyright (c) 2012 - 2020 by Dave Rolsky. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
This is free software, licensed under: |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
The full text of the license can be found in the |
|
146
|
|
|
|
|
|
|
F<LICENSE> file included with this distribution. |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |