blib/lib/Template/Parser/LocalizeNewlines.pm

filter: Statementstmt 76.4% 13 / 17 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 100% 1 / 1 totaltotal 79.1% 19 / 24 CC 1 SCAR 1.5
CC
1
Cov
76%
parse
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
↑ Summary
1 package Template::Parser::LocalizeNewlines;
2  
3 =pod
4  
5 =head1 NAME
6  
7 Template::Parser::LocalizeNewlines - Drop-in replacement Template::Parser that
8 fixes bad newlines
9  
10 =head1 DESCRIPTION
11  
12 L<Template::Parser> has a problem with PRE_CHOMP and related options. They
13 only work on local newlines. If a Template Toolkit instance on a Unix host
14 encounters DOS newlines in a Template, it will fail to chomp the newline
15 correctly, with potentially disasterous results.
16  
17 B<Template::Parser::LocalizeNewlines> is a drop-in replacement that behaves
18 EXACTLY the same (and is a subclass of) as a normal parser, except that
19 before it goes to parse the template content, it applies the newline
20 localisation regex describes in L<http://ali.as/devel/newlines.html>.
21  
22 =head2 Using this Module
23  
24 When creating your Template instance, simple pass an instance of this object
25 along to the constructor.
26  
27 =cut
28  
29 1 ▶use 5.005;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use base 'Template::Parser';
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 1 ▶use vars qw{$VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 $VERSION = '1.04';
36 }
37  
38 # The only method we need to change
39 0 ▶sub parse {
Subroutine parse: not called CC=1 SCAR=6.9
Pod documented
40 0 my $self = shift;
41 0 my $text = shift;
42  
43 # Localise the newlines
44 0 $text =~ s/(?:\015{1,2}\012|\015|\012)/\n/gs;
45  
46 # Pass off to the normal parser
47 0 $self->SUPER::parse( $text, @_ );
48 }
49  
50 1 1;
51  
52 =pod
53  
54 =head1 METHODS
55  
56 This module is identical to L<Template::Parser>.
57  
58 =head1 SUPPORT
59  
60 Bugs should be reported via the following link.
61  
62 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Template-Parser-LocalizeNewlines>
63  
64 For other issues, contact the author.
65  
66 =head1 AUTHOR
67  
68 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
69  
70 =head1 COPYRIGHT
71  
72 Copyright 2004 - 2008 Adam Kennedy.
73  
74 This program is free software; you can redistribute
75 it and/or modify it under the same terms as Perl itself.
76  
77 The full text of the license can be found in the
78 LICENSE file included with this module.
79  
80 =cut
↑ Summary