line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Decl::DefaultFilters;
|
2
|
|
|
|
|
|
|
|
3
|
12
|
|
|
12
|
|
74
|
use warnings;
|
|
12
|
|
|
|
|
27
|
|
|
12
|
|
|
|
|
425
|
|
4
|
12
|
|
|
12
|
|
68
|
use strict;
|
|
12
|
|
|
|
|
26
|
|
|
12
|
|
|
|
|
365
|
|
5
|
12
|
|
|
12
|
|
65
|
use Decl::Util;
|
|
12
|
|
|
|
|
26
|
|
|
12
|
|
|
|
|
1092
|
|
6
|
12
|
|
|
12
|
|
70
|
use Decl::Node;
|
|
12
|
|
|
|
|
29
|
|
|
12
|
|
|
|
|
226
|
|
7
|
12
|
|
|
12
|
|
66
|
use Data::Dumper;
|
|
12
|
|
|
|
|
23
|
|
|
12
|
|
|
|
|
4684
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Decl::DefaultFilters - implements some default filters for the Decl language.
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 VERSION
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Version 0.01
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.01';
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
This isn't really an object module; it's just a place to register the default filters.
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DEFAULT FILTERS
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 hex_filter()
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Called with a string containing hex digits, packs them by pairs into a binary string.
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub hex_filter {
|
36
|
0
|
|
|
0
|
|
0
|
my $value = shift;
|
37
|
0
|
|
|
|
|
0
|
$value =~ s/[^0-9a-fA-F]//g;
|
38
|
0
|
|
|
|
|
0
|
pack ('H*', $value);
|
39
|
|
|
|
|
|
|
}
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 urlencode, urldecode
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
I considered just defining these in HTML::Declarative, but heck, they're useful for testing and not so
|
44
|
|
|
|
|
|
|
big.
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
I considered CPAN's URI::Encode - but I didn't want another dependency for such a small amount of code.
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Source: http://code.activestate.com/recipes/577450-perl-url-encode-and-decode/
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub urlencode {
|
53
|
0
|
|
|
0
|
|
0
|
my $s = shift;
|
54
|
0
|
|
|
|
|
0
|
$s =~ s/ /+/g;
|
55
|
0
|
|
|
|
|
0
|
$s =~ s/([^A-Za-z0-9\+-])/sprintf("%%%02X", ord($1))/seg;
|
|
0
|
|
|
|
|
0
|
|
56
|
0
|
|
|
|
|
0
|
return $s;
|
57
|
|
|
|
|
|
|
}
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub urldecode {
|
60
|
0
|
|
|
0
|
|
0
|
my $s = shift;
|
61
|
0
|
|
|
|
|
0
|
$s =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg;
|
|
0
|
|
|
|
|
0
|
|
62
|
0
|
|
|
|
|
0
|
$s =~ s/\+/ /g;
|
63
|
0
|
|
|
|
|
0
|
return $s;
|
64
|
|
|
|
|
|
|
}
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 init_default_filters()
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Called on initialization of the Decl module.
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub init_default_filters {
|
73
|
12
|
|
|
12
|
|
106
|
Decl->register_filter ('hex', \&hex_filter, 'Decl::DefaultFilters');
|
74
|
12
|
|
|
|
|
56
|
Decl->register_filter ('urlencode', \&urlencode, 'Decl::DefaultFilters');
|
75
|
12
|
|
|
|
|
54
|
Decl->register_filter ('urldecode', \&urldecode, 'Decl::DefaultFilters');
|
76
|
|
|
|
|
|
|
}
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 AUTHOR
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Michael Roberts, C<< >>
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 BUGS
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through
|
85
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll
|
86
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes.
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Copyright 2011 Michael Roberts.
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
93
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published
|
94
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License.
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information.
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; # End of Decl::DefaultFilters
|