File Coverage

blib/lib/Template/Parser/LocalizeNewlines.pm
Criterion Covered Total %
statement 13 17 76.4
branch n/a
condition n/a
subroutine 5 6 83.3
pod 1 1 100.0
total 19 24 79.1


line stmt bran cond sub pod time code
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 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 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.
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     1   1083 use 5.005;
  1         3  
  1         33  
30 1     1   5 use strict;
  1         2  
  1         31  
31 1     1   12 use base 'Template::Parser';
  1         1  
  1         907  
32              
33 1     1   32588 use vars qw{$VERSION};
  1         2  
  1         50  
34             BEGIN {
35 1     1   86 $VERSION = '1.04';
36             }
37              
38             # The only method we need to change
39             sub parse {
40 0     0 1   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;
51              
52             =pod
53              
54             =head1 METHODS
55              
56             This module is identical to L.
57              
58             =head1 SUPPORT
59              
60             Bugs should be reported via the following link.
61              
62             L
63              
64             For other issues, contact the author.
65              
66             =head1 AUTHOR
67              
68             Adam Kennedy Eadamk@cpan.orgE
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