| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package PPIx::EditorTools::ReturnObject; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Simple object to return values from PPIx::EditorTools |
|
4
|
|
|
|
|
|
|
|
|
5
|
11
|
|
|
11
|
|
201
|
use 5.008; |
|
|
11
|
|
|
|
|
49
|
|
|
|
11
|
|
|
|
|
494
|
|
|
6
|
11
|
|
|
11
|
|
65
|
use strict; |
|
|
11
|
|
|
|
|
22
|
|
|
|
11
|
|
|
|
|
353
|
|
|
7
|
11
|
|
|
11
|
|
57
|
use warnings; |
|
|
11
|
|
|
|
|
18
|
|
|
|
11
|
|
|
|
|
349
|
|
|
8
|
11
|
|
|
11
|
|
57
|
use Carp; |
|
|
11
|
|
|
|
|
25
|
|
|
|
11
|
|
|
|
|
4853
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.18'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=pod |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
PPIx::EditorTools::ReturnObject - Simple object to return values from PPIx::EditorTools |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $brace = PPIx::EditorTools::FindUnmatchedBrace->new->find( |
|
21
|
|
|
|
|
|
|
code => "package TestPackage;\nsub x { 1;\n" |
|
22
|
|
|
|
|
|
|
); |
|
23
|
|
|
|
|
|
|
my $location = $brace->element->location; |
|
24
|
|
|
|
|
|
|
my $ppi = $brace->element->ppi; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Retuning a simple C from many of the C |
|
29
|
|
|
|
|
|
|
methods often results in the loss of the overall context for that element. |
|
30
|
|
|
|
|
|
|
C provides an object that can be passed |
|
31
|
|
|
|
|
|
|
around which retains the overall context. |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
For example, in C if the unmatched |
|
34
|
|
|
|
|
|
|
brace were returned by its C the containing |
|
35
|
|
|
|
|
|
|
C is likely to go out of scope, thus the C |
|
36
|
|
|
|
|
|
|
method no longer returns a valid location (rather it returns undef). |
|
37
|
|
|
|
|
|
|
Using the C preserves the C and the containing |
|
38
|
|
|
|
|
|
|
context. |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 METHODS |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=over 4 |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=item new() |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Constructor which should be used by C. Accepts the following |
|
47
|
|
|
|
|
|
|
named parameters: |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=over 4 |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=item ppi |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
A C representing the (possibly modified) code. |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item code |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
A string representing the (possibly modified) code. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item element |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
A C or a subclass thereof representing the interesting element. |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=back |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item ppi |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Accessor to retrieve the C. May create the C |
|
68
|
|
|
|
|
|
|
from the $code string (lazily) if needed. |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item code |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Accessor to retrieve the string representation of the code. May be retrieved |
|
73
|
|
|
|
|
|
|
from the C via the serialize method (lazily) if needed. |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=back |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub new { |
|
80
|
22
|
|
|
22
|
1
|
1494
|
my $class = shift; |
|
81
|
22
|
|
33
|
|
|
372
|
return bless {@_}, ref($class) || $class; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub element { |
|
85
|
14
|
|
|
14
|
1
|
16148
|
my ($self) = @_; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# If element is a code ref, run the code once then cache the |
|
88
|
|
|
|
|
|
|
# result |
|
89
|
14
|
100
|
33
|
|
|
192
|
if ( exists $self->{element} |
|
|
|
|
66
|
|
|
|
|
|
90
|
|
|
|
|
|
|
and ref( $self->{element} ) |
|
91
|
|
|
|
|
|
|
and ref( $self->{element} ) eq 'CODE' ) |
|
92
|
|
|
|
|
|
|
{ |
|
93
|
2
|
|
|
|
|
9
|
$self->{element} = $self->{element}->(@_); |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
14
|
|
|
|
|
215
|
return $self->{element}; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub ppi { |
|
100
|
3
|
|
|
3
|
1
|
9
|
my ( $self, $doc ) = @_; |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# $self->{ppi} = $doc if $doc; # TODO: and isa? |
|
103
|
|
|
|
|
|
|
|
|
104
|
3
|
100
|
|
|
|
17
|
return $self->{ppi} if $self->{ppi}; |
|
105
|
|
|
|
|
|
|
|
|
106
|
2
|
50
|
|
|
|
8
|
if ( $self->{code} ) { |
|
107
|
2
|
|
|
|
|
11
|
my $code = $self->{code}; |
|
108
|
2
|
|
|
|
|
13
|
$self->{ppi} = PPI::Document->new( \$code ); |
|
109
|
2
|
|
|
|
|
17896
|
return $self->{ppi}; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
0
|
return; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub code { |
|
116
|
16
|
|
|
16
|
1
|
1677
|
my ( $self, $doc ) = @_; |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# $self->{code} = $doc if $doc; |
|
119
|
|
|
|
|
|
|
|
|
120
|
16
|
100
|
|
|
|
109
|
return $self->{code} if $self->{code}; |
|
121
|
|
|
|
|
|
|
|
|
122
|
12
|
50
|
|
|
|
54
|
if ( $self->{ppi} ) { |
|
123
|
12
|
|
|
|
|
64
|
$self->{code} = $self->{ppi}->serialize; |
|
124
|
12
|
|
|
|
|
9561
|
return $self->{code}; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
return; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |