File Coverage

blib/lib/PPI/Token/Data.pm
Criterion Covered Total %
statement 27 27 100.0
branch 3 4 75.0
condition n/a
subroutine 8 8 100.0
pod 1 1 100.0
total 39 40 97.5


line stmt bran cond sub pod time code
1             package PPI::Token::Data;
2              
3             =pod
4              
5             =head1 NAME
6              
7             PPI::Token::Data - The actual data in the __DATA__ section of a file
8              
9             =head1 INHERITANCE
10              
11             PPI::Token::Data
12             isa PPI::Token
13             isa PPI::Element
14              
15             =head1 DESCRIPTION
16              
17             The C class is used to represent the actual data inside
18             a file's C<__DATA__> section.
19              
20             One C object is used to represent the entire of the data,
21             primarily so that it can provide a convenient handle directly to the data.
22              
23             =head1 METHODS
24              
25             C provides one method in addition to those provided by
26             our parent L and L classes.
27              
28             =cut
29              
30 64     64   351 use strict;
  64         119  
  64         1448  
31 64     64   263 use PPI::Token ();
  64         109  
  64         1332  
32              
33             # IO::String emulates file handles using in memory strings. Perl can do this
34             # directly on perl 5.8+
35 64     64   261 use constant USE_IO_STRING => $] < '5.008000';
  64         92  
  64         4172  
36 64     64   1365 use if USE_IO_STRING, 'IO::String';
  64         118  
  64         466  
37             # code may expect methods to be available on all file handles, so make sure
38             # IO is loaded
39 64     64   2216 use if !USE_IO_STRING, 'IO::File';
  64         102  
  64         186  
40              
41             our $VERSION = '1.275';
42              
43             our @ISA = "PPI::Token";
44              
45              
46              
47              
48              
49             #####################################################################
50             # Methods
51              
52             =pod
53              
54             =head2 handle
55              
56             The C method returns a L handle that allows you
57             to do all the normal handle-y things to the contents of the __DATA__
58             section of the file.
59              
60             Unlike in perl itself, this means you can also do things like C
61             new data onto the end of the __DATA__ section, or modify it with
62             any other process that can accept an L as input or output.
63              
64             Returns an L object.
65              
66             =cut
67              
68             sub handle {
69 1     1 1 458 my $self = shift;
70             # perl 5.6 compatibility
71 1         2 if (USE_IO_STRING) {
72             return IO::String->new( \$self->{content} );
73             }
74             else {
75 1     1   29 open my $fh, '+<', \$self->{content};
  1         6  
  1         2  
  1         5  
76 1         616 return $fh;
77             }
78             }
79              
80             sub __TOKENIZER__on_line_start {
81 6     6   13 my ( $self, $t ) = @_;
82              
83             # Add the line
84 6 100       18 if ( defined $t->{token} ) {
85 3         172 $t->{token}->{content} .= $t->{line};
86             }
87             else {
88 3 50       22 defined( $t->{token} = $t->{class}->new( $t->{line} ) ) or return undef;
89             }
90              
91 6         15 return 0;
92             }
93              
94             1;
95              
96             =pod
97              
98             =head1 SUPPORT
99              
100             See the L in the main module.
101              
102             =head1 AUTHOR
103              
104             Adam Kennedy Eadamk@cpan.orgE
105              
106             =head1 COPYRIGHT
107              
108             Copyright 2001 - 2011 Adam Kennedy.
109              
110             This program is free software; you can redistribute
111             it and/or modify it under the same terms as Perl itself.
112              
113             The full text of the license can be found in the
114             LICENSE file included with this module.
115              
116             =cut