blib/lib/Decl/StandardFilters.pm

filter: Statementstmt 60.6% 20 / 33 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod n/a totaltotal 61.9% 26 / 42 CC 1 SCAR 2.9
CC
1
Cov
61%
hex_filter
2.0
urlencode
2.0
urldecode
2.0
CRAP 1.3
« lib/Decl/Semantics/POD.pm ↑ Summary
1 package Decl::DefaultFilters;
2
3 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use Decl::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use Decl::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 13 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 13 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 0 ▶sub hex_filter {
Subroutine hex_filter: not called CC=1 SCAR=6.9
36 0 my $value = shift;
37 0 $value =~ s/[^0-9a-fA-F]//g;
38 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 0 ▶sub urlencode {
Subroutine urlencode: not called CC=1 SCAR=6.9
53 0 my $s = shift;
54 0 $s =~ s/ /+/g;
55 0 $s =~ s/([^A-Za-z0-9\+-])/sprintf("%%%02X", ord($1))/seg;
56 0 return $s;
57 }
58
59 0 ▶sub urldecode {
Subroutine urldecode: not called CC=1 SCAR=6.9
60 0 my $s = shift;
61 0 $s =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg;
62 0 $s =~ s/\+/ /g;
63 0 return $s;
64 }
65
66 =head2 init_default_filters()
67
68 Called on initialization of the Decl module.
69
70 =cut
71
72 13 ▶sub init_default_filters {
Subroutine init_default_filters: called CC=1 SCAR=0.0
73 13 Decl->register_filter ('hex', \&hex_filter, 'Decl::DefaultFilters');
74 13 Decl->register_filter ('urlencode', \&urlencode, 'Decl::DefaultFilters');
75 13 Decl->register_filter ('urldecode', \&urldecode, 'Decl::DefaultFilters');
76 }
77
78 =head1 AUTHOR
79
80 Michael Roberts, C<< <michael at vivtek.com> >>
81
82 =head1 BUGS
83
84 Please report any bugs or feature requests to C<bug-decl at rt.cpan.org>, or through
85 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Decl>. 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 13 1; # End of Decl::DefaultFilters
« lib/Decl/Semantics/POD.pm ↑ Summary