PPI/Document/File.pm

filter: Statementstmt 75.8% 22 / 29 Branchbran 37.5% 3 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 100% 2 / 2 totaltotal 71.1% 32 / 45 CC 5 SCAR 12.3
CC
5
Cov
68%
save
6.0
new
4.6
BEGIN
1.0
CRAP 3.4
« PPI/Token/Comment.pm ↑ Summary PPI/Token/BOM.pm »
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 63 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 63 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 63 ▶use Params::Util qw{_STRING _INSTANCE};
Subroutine BEGIN: called CC=1 SCAR=0.0
23 63 ▶use PPI::Document ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 63 our $VERSION = '1.260'; # VERSION
26  
27 63 our @ISA = 'PPI::Document';
28  
29  
30  
31  
32  
33 #####################################################################
34 # Constructor and Accessors
35  
36 =pod
37  
38 =head2 new
39  
40 my $file = PPI::Document::File->new( 'Module.pm' );
41  
42 The C<new> constructor works the same as for the regular one, except
43 that the only params allowed is a file name. You cannot create an
44 "anonymous" PPI::Document::File object, not can you create an empty one.
45  
46 Returns a new PPI::Document::File object, or C<undef> on error.
47  
48 =cut
49  
50 sub new {
51 3 ▶ my $class = shift;
Subroutine new: called CC=4 SCAR=15.2
Pod documented
52 3 my $filename = _STRING(shift);
53 3 ▶ unless ( defined $filename ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $filename) 0 3 3
54 # Perl::Critic got a complaint about not handling a file
55 # named "0".
56 0 return $class->_error("Did not provide a file name to load");
57 }
58  
59 # Load the Document
60 3 ▶ my $self = $class->SUPER::new( $filename, @_ ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $self = $class->SUPER::new($filename, @_) or return undef 0 3 3
61  
62 # Unlike a normal inheritance situation, due to our need to stay
63 # compatible with caching magic, this actually returns a regular
64 # anonymous document. We need to rebless if
65 3 ▶ if ( _INSTANCE($self, 'PPI::Document') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_INSTANCE($self, 'PPI::Document')) { } 3 0 3
66 3 bless $self, 'PPI::Document::File';
67 } else {
68 0 die "PPI::Document::File SUPER call returned an object of the wrong type";
69 }
70  
71 3 $self;
72 }
73  
74 =pod
75  
76 =head2 save
77  
78 # Save to the file we were loaded from
79 $file->save;
80
81 # Save a copy to somewhere else
82 $file->save( 'Module2.pm' );
83  
84 The C<save> method works similarly to the one in the parent L<PPI::Document>
85 class, saving a copy of the document to a file.
86  
87 The difference with this subclass is that if C<save> is not passed any
88 filename, it will save it back to the file it was loaded from.
89  
90 Note: When saving to a different file, it is considered to be saving a
91 B<copy> and so the value returned by the C<filename> accessor will stay
92 the same, and not change to the new filename.
93  
94 =cut
95  
96 sub save {
97 0 ▶ my $self = shift;
Subroutine save: not called CC=2 SCAR=17.9
Pod documented
98  
99 # Save to where?
100 0 my $filename = shift;
101 0 ▶ unless ( defined $filename ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $filename) 0 0 0
102 0 $filename = $self->filename;
103 }
104  
105 # Hand off to main save method
106 0 $self->SUPER::save( $filename, @_ );
107 }
108  
109 63 1;
110  
111 =pod
112  
113 =head1 TO DO
114  
115 - May need to overload some methods to forcefully prevent Document
116 objects becoming children of another Node.
117  
118 =head1 SUPPORT
119  
120 See the L<support section|PPI/SUPPORT> in the main module.
121  
122 =head1 AUTHOR
123  
124 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
125  
126 =head1 COPYRIGHT
127  
128 Copyright 2001 - 2011 Adam Kennedy.
129  
130 This program is free software; you can redistribute
131 it and/or modify it under the same terms as Perl itself.
132  
133 The full text of the license can be found in the
134 LICENSE file included with this module.
135  
136 =cut
« PPI/Token/Comment.pm ↑ Summary PPI/Token/BOM.pm »