line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Plugin::StripComments; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
############################################################################### |
4
|
|
|
|
|
|
|
# Required inclusions. |
5
|
|
|
|
|
|
|
############################################################################### |
6
|
1
|
|
|
1
|
|
57187
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
7
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
8
|
1
|
|
|
1
|
|
5
|
use base qw(Template::Plugin::Filter); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
568
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
############################################################################### |
11
|
|
|
|
|
|
|
# Version number. |
12
|
|
|
|
|
|
|
############################################################################### |
13
|
|
|
|
|
|
|
our $VERSION = '1.02'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
############################################################################### |
16
|
|
|
|
|
|
|
# Subroutine: init() |
17
|
|
|
|
|
|
|
############################################################################### |
18
|
|
|
|
|
|
|
# Initializes the template plugin. |
19
|
|
|
|
|
|
|
############################################################################### |
20
|
|
|
|
|
|
|
sub init { |
21
|
6
|
|
|
6
|
1
|
18044
|
my $self = shift; |
22
|
6
|
|
|
|
|
16
|
$self->{'_DYNAMIC'} = 1; |
23
|
6
|
|
50
|
|
|
40
|
$self->install_filter( $self->{'_ARGS'}->[0] || 'stripcomments' ); |
24
|
6
|
|
|
|
|
256
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
############################################################################### |
28
|
|
|
|
|
|
|
# Subroutine: filter($text) |
29
|
|
|
|
|
|
|
############################################################################### |
30
|
|
|
|
|
|
|
# Filters the given text, removing comment blocks as necessary. |
31
|
|
|
|
|
|
|
############################################################################### |
32
|
|
|
|
|
|
|
sub filter { |
33
|
6
|
|
|
6
|
1
|
513
|
my ($self, $text) = @_; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# C-style comments |
36
|
6
|
|
|
|
|
35
|
$text =~ s{/\*.*?\*/}{}sg; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# HTML style comments |
39
|
6
|
|
|
|
|
24
|
$text =~ s{}{}sg; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Return the filtered text back to the caller |
42
|
6
|
|
|
|
|
38
|
return $text; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 NAME |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Template::Plugin::StripComments - Template Toolkit filter to strip comment blocks |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
[% USE StripComments %] |
54
|
|
|
|
|
|
|
... |
55
|
|
|
|
|
|
|
[% FILTER stripcomments %] |
56
|
|
|
|
|
|
|
/* C-style block comments get removed */ |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
[% END %] |
60
|
|
|
|
|
|
|
... |
61
|
|
|
|
|
|
|
[% text | stripcomments %] |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 DESCRIPTION |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
C is a filter plugin for L, |
66
|
|
|
|
|
|
|
which strips comment blocks from the filtered text. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
The following types of comment blocks are stripped: |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=over |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item /* c-style comments */ |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=back |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 METHODS |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=over |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=item init() |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Initializes the template plugin. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item filter($text) |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Filters the given text, removing comment blocks as necessary. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=back |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 AUTHOR |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Graham TerMarsch |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 COPYRIGHT |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Copyright (C) 2007, Graham TerMarsch. All Rights Reserved. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under the same |
101
|
|
|
|
|
|
|
terms as Perl itself. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 SEE ALSO |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
L. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |