PPI/Token/BOM.pm

filter: Statementstmt 95.0% 19 / 20 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 89.6% 26 / 29 CC 4 SCAR 11.2
CC
4
Cov
88%
__TOKENIZER__on_line_start
4.1
BEGIN
1.0
BEGIN
1.0
CRAP 3.1
« PPI/Document/File.pm ↑ Summary PPI/Token/_QuoteEngine/Simple.pm »
1 package PPI::Token::BOM;
2  
3 =pod
4  
5 =head1 NAME
6  
7 PPI::Token::BOM - Tokens representing Unicode byte order marks
8  
9 =head1 INHERITANCE
10  
11 PPI::Token::BOM
12 isa PPI::Token
13 isa PPI::Element
14  
15 =head1 DESCRIPTION
16  
17 This is a special token in that it can only occur at the beginning of
18 documents. If a BOM byte mark occurs elsewhere in a file, it should
19 be treated as L<PPI::Token::Whitespace>. We recognize the byte order
20 marks identified at this URL:
21 L<http://www.unicode.org/faq/utf_bom.html#BOM>
22  
23 UTF-32, big-endian 00 00 FE FF
24 UTF-32, little-endian FF FE 00 00
25 UTF-16, big-endian FE FF
26 UTF-16, little-endian FF FE
27 UTF-8 EF BB BF
28  
29 Note that as of this writing, PPI only has support for UTF-8
30 (namely, in POD and strings) and no support for UTF-16 or UTF-32. We
31 support the BOMs of the latter two for completeness only.
32  
33 The BOM is considered non-significant, like white space.
34  
35 =head1 METHODS
36  
37 There are no additional methods beyond those provided by the parent
38 L<PPI::Token> and L<PPI::Element> classes.
39  
40 =cut
41  
42 63 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 63 ▶use PPI::Token ();
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 63 our $VERSION = '1.260'; # VERSION
46  
47 63 our @ISA = "PPI::Token";
48  
49 sub significant() { '' }
50  
51  
52  
53  
54  
55 #####################################################################
56 # Parsing Methods
57  
58 63 my %bom_types = (
59 "\x00\x00\xfe\xff" => 'UTF-32',
60 "\xff\xfe\x00\x00" => 'UTF-32',
61 "\xfe\xff" => 'UTF-16',
62 "\xff\xfe" => 'UTF-16',
63 "\xef\xbb\xbf" => 'UTF-8',
64 );
65  
66 sub __TOKENIZER__on_line_start {
67 16012 ▶ my $t = $_[1];
Subroutine __TOKENIZER__on_line_start: called CC=4 SCAR=14.1
68 16012 $_ = $t->{line};
69  
70 16012 ▶ if (m/^(\x00\x00\xfe\xff | # UTF-32, big-endian
Branch: 1 branch
BranchTrueFalseTotal
if (/^(\x00\x00\xfe\xff | # UTF-32, big-endian \xff\xfe\x00\x00 | # UTF-32, little-endian \xfe\xff | # UTF-16, big-endian \xff\xfe | # UTF-16, little-endian \xef\xbb\xbf) # UTF-8 /sx) 2 16010 16012
71 \xff\xfe\x00\x00 | # UTF-32, little-endian
72 \xfe\xff | # UTF-16, big-endian
73 \xff\xfe | # UTF-16, little-endian
74 \xef\xbb\xbf) # UTF-8
75 /xs) {
76 2 my $bom = $1;
77  
78 2 ▶ if ($bom_types{$bom} ne 'UTF-8') {
Branch: 1 branch
BranchTrueFalseTotal
if ($bom_types{$bom} ne "UTF-8") 0 2 2
79 0 return $t->_error("$bom_types{$bom} is not supported");
80 }
81  
82 2 ▶ $t->_new_token('BOM', $bom) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$t->_new_token("BOM", $bom) or return undef 0 2 2
83 2 $t->{line_cursor} += length $bom;
84 }
85  
86 # Continue just as if there was no BOM
87 16012 $t->{class} = 'PPI::Token::Whitespace';
88 16012 return $t->{class}->__TOKENIZER__on_line_start($t);
89 }
90  
91 63 1;
92  
93 =pod
94  
95 =head1 SUPPORT
96  
97 See the L<support section|PPI/SUPPORT> in the main module
98  
99 =head1 AUTHOR
100  
101 Chris Dolan E<lt>cdolan@cpan.orgE<gt>
102  
103 =head1 COPYRIGHT
104  
105 Copyright 2001 - 2011 Adam Kennedy.
106  
107 This program is free software; you can redistribute
108 it and/or modify it under the same terms as Perl itself.
109  
110 The full text of the license can be found in the
111 LICENSE file included with this module.
112  
113 =cut
« PPI/Document/File.pm ↑ Summary PPI/Token/_QuoteEngine/Simple.pm »