blib/lib/Template/Plugin/Body.pm

filter: Statementstmt 75.0% 18 / 24 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 3 totaltotal 64.1% 25 / 39 CC 2 SCAR 7.4
CC
2
Cov
69%
init
6.0
filter
2.0
BEGIN
1.0
CRAP 2.1
↑ Summary
1 package Template::Plugin::Body;
2  
3 =pod
4  
5 =head1 NAME
6  
7 Template::Plugin::Body - Strip HTML to just keep the body content
8  
9 =head1 SYNOPSIS
10  
11 # _included.html
12 <html>
13 <head>
14 <style ...>
15 </head>
16 <body>
17 This is content we need the stylesheet to see properly.
18 </body>
19 </html>
20
21 # mypage.html
22 [% USE Body %]
23 <html>
24 <head>
25 <style ...>
26 </head>
27 <body>
28 Some content
29 [% INCLUDE _included.html | Body %]
30 Some more content
31 </body>
32 </html>
33  
34 =head1 DESCRIPTION
35  
36 The things we do to support designers...
37  
38 When you are including a big chunk of HTML into a page via an include, you
39 can have problems editing it in WYSIWYG editors because it won't have the
40 stylesheets, meta tags and javascript libs that the main document does.
41  
42 So for the sake of designers, the best solution is to provide the includes
43 with full HTML headers, including proper styles and so on. They can do what
44 they like in Dreamweaver or Editor De Jour. Then when including, we strip
45 the wrapping off to get just the content.
46  
47 And that's what this module does. It removes everything to keep only what
48 is B<inside> the body tags.
49  
50 =cut
51  
52 2 ▶use 5.005;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 2 ▶use base 'Template::Plugin::Filter';
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 2 ▶use vars qw{$VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
57 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
58 2 $VERSION = '1.04';
59 }
60  
61  
62  
63  
64  
65 #####################################################################
66 # Template::Plugin::Filter Methods
67  
68 0 ▶sub init {
Subroutine init: not called CC=2 SCAR=17.9
Pod undocumented
69 0 my $self = shift;
70 0 ▶ my $name = $self->{_CONFIG}->{name} || 'Body';
Condition0%0/2
$self->{'_CONFIG'}{'name'} || 'Body'
l!l
00
MC/DC0%0/1
$self->{'_CONFIG'}{'name'} || 'Body'
$self->{'_CONFIG'}{'name'}
Truth table0%0/2
A
A= $self->{'_CONFIG'}{'name'}
Aresult
11
00
71 0 $self->install_filter($name);
72 0 $self;
73 }
74  
75 1 ▶sub coderef {
Subroutine coderef: called CC=1 SCAR=0.0
Pod undocumented
76 1 \&_filter;
77 }
78  
79 0 ▶sub filter {
Subroutine filter: not called CC=1 SCAR=6.9
Pod undocumented
80 0 my ($self, $text) = @_;
81 0 _filter( $text );
82 }
83  
84 4 ▶sub _filter {
Subroutine _filter: called CC=1 SCAR=0.0
85 4 my $text = shift;
86  
87 # Strip away everything before the <body> tag
88 4 $text =~ s/\A.*?<body.*?>//is;
89 4 $text =~ s/<\/body>.*?\z//is;
90  
91 4 $text;
92 }
93  
94 2 1;
95  
96 =pod
97  
98 =head1 SUPPORT
99  
100 Bugs should be submitted via the CPAN bug tracker, located at
101  
102 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Template-Plugin-Body>
103  
104 For other issues, or commercial enhancement or support, contact the author.
105  
106 =head1 AUTHOR
107  
108 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
109  
110 =head1 ACKOWLEDGEMENTS
111  
112 Thank you to Phase N Australia (L<http://phase-n.com/>) for permitting the
113 open sourcing and release of this distribution as a spin-off from a
114 commercial project.
115  
116 =head1 COPYRIGHT
117  
118 Copyright 2005 - 2008 Adam Kennedy.
119  
120 This program is free software; you can redistribute
121 it and/or modify it under the same terms as Perl itself.
122  
123 The full text of the license can be found in the
124 LICENSE file included with this module.
125  
126 =cut
↑ Summary