Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Document/File.pm |
Statements | Executed 1312 statements in 9.08ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
144 | 1 | 1 | 6.51ms | 13.3s | new | PPI::Document::File::
291 | 3 | 3 | 739µs | 739µs | filename | PPI::Document::File::
1 | 1 | 1 | 13µs | 26µs | BEGIN@20 | PPI::Document::File::
1 | 1 | 1 | 8µs | 8µs | BEGIN@26 | PPI::Document::File::
1 | 1 | 1 | 7µs | 33µs | BEGIN@22 | PPI::Document::File::
1 | 1 | 1 | 7µs | 36µs | BEGIN@25 | PPI::Document::File::
1 | 1 | 1 | 3µs | 3µs | BEGIN@23 | PPI::Document::File::
1 | 1 | 1 | 3µs | 3µs | BEGIN@21 | PPI::Document::File::
0 | 0 | 0 | 0s | 0s | save | PPI::Document::File::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package PPI::Document::File; | ||||
2 | |||||
3 | =pod | ||||
4 | |||||
5 | =head1 NAME | ||||
6 | |||||
7 | PPI::Document::File - A Perl Document located in a specific file | ||||
8 | |||||
9 | =head1 DESCRIPTION | ||||
10 | |||||
11 | B<WARNING: This class is experimental, and may change without notice> | ||||
12 | |||||
13 | B<PPI::Document::File> provides a L<PPI::Document> subclass that represents | ||||
14 | a Perl document stored in a specific named file. | ||||
15 | |||||
16 | =head1 METHODS | ||||
17 | |||||
18 | =cut | ||||
19 | |||||
20 | 2 | 20µs | 2 | 38µs | # spent 26µs (13+13) within PPI::Document::File::BEGIN@20 which was called:
# once (13µs+13µs) by PPI::BEGIN@24 at line 20 # spent 26µs making 1 call to PPI::Document::File::BEGIN@20
# spent 13µs making 1 call to strict::import |
21 | 2 | 19µs | 1 | 3µs | # spent 3µs within PPI::Document::File::BEGIN@21 which was called:
# once (3µs+0s) by PPI::BEGIN@24 at line 21 # spent 3µs making 1 call to PPI::Document::File::BEGIN@21 |
22 | 2 | 23µs | 2 | 58µs | # spent 33µs (7+25) within PPI::Document::File::BEGIN@22 which was called:
# once (7µs+25µs) by PPI::BEGIN@24 at line 22 # spent 33µs making 1 call to PPI::Document::File::BEGIN@22
# spent 25µs making 1 call to Exporter::import |
23 | 2 | 20µs | 1 | 3µs | # spent 3µs within PPI::Document::File::BEGIN@23 which was called:
# once (3µs+0s) by PPI::BEGIN@24 at line 23 # spent 3µs making 1 call to PPI::Document::File::BEGIN@23 |
24 | |||||
25 | 2 | 28µs | 2 | 64µs | # spent 36µs (7+29) within PPI::Document::File::BEGIN@25 which was called:
# once (7µs+29µs) by PPI::BEGIN@24 at line 25 # spent 36µs making 1 call to PPI::Document::File::BEGIN@25
# spent 29µs making 1 call to vars::import |
26 | # spent 8µs within PPI::Document::File::BEGIN@26 which was called:
# once (8µs+0s) by PPI::BEGIN@24 at line 29 | ||||
27 | 1 | 400ns | $VERSION = '1.215'; | ||
28 | 1 | 9µs | @ISA = 'PPI::Document'; | ||
29 | 1 | 149µs | 1 | 8µs | } # spent 8µs making 1 call to PPI::Document::File::BEGIN@26 |
30 | |||||
- - | |||||
35 | ##################################################################### | ||||
36 | # Constructor and Accessors | ||||
37 | |||||
38 | =pod | ||||
39 | |||||
40 | =head2 new | ||||
41 | |||||
42 | my $file = PPI::Document::File->new( 'Module.pm' ); | ||||
43 | |||||
44 | The C<new> constructor works the same as for the regular one, except | ||||
45 | that the only params allowed is a file name. You cannot create an | ||||
46 | "anonymous" PPI::Document::File object, not can you create an empty one. | ||||
47 | |||||
48 | Returns a new PPI::Document::File object, or C<undef> on error. | ||||
49 | |||||
50 | =cut | ||||
51 | |||||
52 | # spent 13.3s (6.51ms+13.2) within PPI::Document::File::new which was called 144 times, avg 92.0ms/call:
# 144 times (6.51ms+13.2s) by Perl::Critic::Document::_init_from_external_source at line 106 of Perl/Critic/Document.pm, avg 92.0ms/call | ||||
53 | 144 | 75µs | my $class = shift; | ||
54 | 144 | 603µs | 144 | 218µs | my $filename = _STRING(shift); # spent 218µs making 144 calls to Params::Util::_STRING, avg 2µs/call |
55 | 144 | 53µs | unless ( defined $filename ) { | ||
56 | # Perl::Critic got a complaint about not handling a file | ||||
57 | # named "0". | ||||
58 | return $class->_error("Did not provide a file name to load"); | ||||
59 | } | ||||
60 | |||||
61 | # Load the Document | ||||
62 | 144 | 4.48ms | 288 | 13.2s | my $self = $class->SUPER::new( $filename, @_ ) or return undef; # spent 13.2s making 144 calls to PPI::Document::new, avg 92.0ms/call
# spent 99µs making 144 calls to PPI::Util::TRUE, avg 686ns/call |
63 | |||||
64 | # Unlike a normal inheritance situation, due to our need to stay | ||||
65 | # compatible with caching magic, this actually returns a regular | ||||
66 | # anonymous document. We need to rebless if | ||||
67 | 144 | 1.76ms | 432 | 1.16ms | if ( _INSTANCE($self, 'PPI::Document') ) { # spent 919µs making 144 calls to Params::Util::_INSTANCE, avg 6µs/call
# spent 148µs making 144 calls to UNIVERSAL::isa, avg 1µs/call
# spent 94µs making 144 calls to PPI::Util::TRUE, avg 653ns/call |
68 | bless $self, 'PPI::Document::File'; | ||||
69 | } else { | ||||
70 | die "PPI::Document::File SUPER call returned an object of the wrong type"; | ||||
71 | } | ||||
72 | |||||
73 | # Save the filename | ||||
74 | 144 | 320µs | $self->{filename} = $filename; | ||
75 | |||||
76 | 144 | 530µs | $self; | ||
77 | } | ||||
78 | |||||
79 | =head2 filename | ||||
80 | |||||
81 | The C<filename> accessor returns the name of the file in which the document | ||||
82 | is stored. | ||||
83 | |||||
84 | =cut | ||||
85 | |||||
86 | # spent 739µs within PPI::Document::File::filename which was called 291 times, avg 3µs/call:
# 144 times (414µs+0s) by PPI::Document::index_locations at line 611 of PPI/Document.pm, avg 3µs/call
# 144 times (318µs+0s) by Perl::Critic::Document::filename at line 342 of Perl/Critic/Document.pm, avg 2µs/call
# 3 times (6µs+0s) by Perl::Critic::Violation::new at line 86 of Perl/Critic/Violation.pm, avg 2µs/call | ||||
87 | 291 | 991µs | $_[0]->{filename}; | ||
88 | } | ||||
89 | |||||
90 | =pod | ||||
91 | |||||
92 | =head2 save | ||||
93 | |||||
94 | # Save to the file we were loaded from | ||||
95 | $file->save; | ||||
96 | |||||
97 | # Save a copy to somewhere else | ||||
98 | $file->save( 'Module2.pm' ); | ||||
99 | |||||
100 | The C<save> method works similarly to the one in the parent L<PPI::Document> | ||||
101 | class, saving a copy of the document to a file. | ||||
102 | |||||
103 | The difference with this subclass is that if C<save> is not passed any | ||||
104 | filename, it will save it back to the file it was loaded from. | ||||
105 | |||||
106 | Note: When saving to a different file, it is considered to be saving a | ||||
107 | B<copy> and so the value returned by the C<filename> accessor will stay | ||||
108 | the same, and not change to the new filename. | ||||
109 | |||||
110 | =cut | ||||
111 | |||||
112 | sub save { | ||||
113 | my $self = shift; | ||||
114 | |||||
115 | # Save to where? | ||||
116 | my $filename = shift; | ||||
117 | unless ( defined $filename ) { | ||||
118 | $filename = $self->filename; | ||||
119 | } | ||||
120 | |||||
121 | # Hand off to main save method | ||||
122 | $self->SUPER::save( $filename, @_ ); | ||||
123 | } | ||||
124 | |||||
125 | 1 | 2µs | 1; | ||
126 | |||||
127 | =pod | ||||
128 | |||||
129 | =head1 TO DO | ||||
130 | |||||
131 | - May need to overload some methods to forcefully prevent Document | ||||
132 | objects becoming children of another Node. | ||||
133 | |||||
134 | =head1 SUPPORT | ||||
135 | |||||
136 | See the L<support section|PPI/SUPPORT> in the main module. | ||||
137 | |||||
138 | =head1 AUTHOR | ||||
139 | |||||
140 | Adam Kennedy E<lt>adamk@cpan.orgE<gt> | ||||
141 | |||||
142 | =head1 COPYRIGHT | ||||
143 | |||||
144 | Copyright 2001 - 2011 Adam Kennedy. | ||||
145 | |||||
146 | This program is free software; you can redistribute | ||||
147 | it and/or modify it under the same terms as Perl itself. | ||||
148 | |||||
149 | The full text of the license can be found in the | ||||
150 | LICENSE file included with this module. | ||||
151 | |||||
152 | =cut |