Transform/using/HTML/Meta.pm

filter: Statementstmt 94.1% 32 / 34 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 100% 3 / 3 totaltotal 90.0% 45 / 50 CC 4 SCAR 6.5
CC
4
Cov
90%
new
3.1
parse_string
2.0
parse_file
2.0
CRAP 1.9
« Transform/SAX/Filter.pm ↑ Summary Transform/using/XML/SAX.pm »
1 package URL::Transform::using::HTML::Meta;
2  
3 =head1 NAME
4  
5 URL::Transform::using::HTML::Meta - regular expression parsing of the meta content attribute for url transformation
6  
7 =head1 SYNOPSIS
8  
9 my $urlt = URL::Transform::using::HTML::Meta->new(
10 'output_function' => sub { $output .= "@_" },
11 'transform_function' => sub { return (join '|', @_) },
12 );
13 $urlt->parse_string("0;url = 'some other link'");
14  
15 print "and this is the output: ", $output;
16  
17  
18 =head1 DESCRIPTION
19  
20 Using module you can performs an url transformation on the HTML META
21 content attribute string.
22  
23 This module is used by L<URL::Transform>.
24  
25 =cut
26  
27 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 2 our $VERSION = '0.01';
31  
32 2 ▶use Carp::Clan;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 2 ▶use base 'Class::Accessor::Fast';
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36  
37 2 my $META_URL_REGEXP = qr{ # ex. "0;URL=http://some.server.com/"
38 ^ ( # capture non url path of the string
39 \s*
40 [0-9]+ # number of seconds after which to refresh
41 \s*
42 ;
43 \s*
44 url\s*= # url= (case insensitive)
45 \s*
46 ['"]?
47 )
48 ( # the rest is url
49 .+
50 )
51 (
52 ['"]?
53 \s*
54 )
55 $
56 }xmsi;
57  
58  
59 =head1 PROPERTIES
60  
61 output_function
62 transform_function
63  
64 =cut
65  
66 2 __PACKAGE__->mk_accessors(qw{
67 output_function
68 transform_function
69 });
70  
71 =head1 METHODS
72  
73 =cut
74  
75  
76 =head2 new
77  
78 Object constructor.
79  
80 Requires:
81  
82 output_function
83 transform_function
84  
85 =cut
86  
87 3 ▶sub new {
Subroutine new: called CC=3 SCAR=11.2
Pod documented
88 3 my $class = shift;
89  
90 3 my $self = $class->SUPER::new({ @_ });
91  
92 3 my $output_function = $self->output_function;
93 3 my $transform_function = $self->transform_function;
94
95 3 ▶ croak 'pass print function'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $output_function eq "CODE" 0 3 3
96 if not (ref $output_function eq 'CODE');
97
98 3 ▶ croak 'pass transform url function'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $transform_function eq "CODE" 0 3 3
99 if not (ref $transform_function eq 'CODE');
100
101 3 return $self;
102 }
103  
104  
105 =head2 parse_string($string)
106  
107 Submit meta content string for parsing.
108  
109 =cut
110  
111 3 ▶sub parse_string {
Subroutine parse_string: called CC=2 SCAR=6.9
Pod documented
112 3 my $self = shift;
113 3 my $string = shift;
114
115 3 ▶ if ($string =~ $META_URL_REGEXP) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$META_URL_REGEXP/imsx) { } 2 1 3
116 2 my $meta_content_start = $1;
117 2 my $url = $2;
118 2 my $meta_content_end = $3;
119
120 2 $url = $self->transform_function->(
121 'tag_name' => 'meta',
122 'attribute_name' => 'content',
123 'url' => $url,
124 );
125
126 2 $self->output_function->(
127 $meta_content_start.$url.$meta_content_end
128 );
129 }
130 else {
131 1 $self->output_function->($string);
132 }
133  
134 }
135  
136  
137 =head2 parse_file($file_name)
138  
139 makes no sense in this case.
140  
141 =cut
142  
143 0 ▶sub parse_file {
Subroutine parse_file: not called CC=1 SCAR=6.9
Pod documented
144 0 my $self = shift;
145
146 0 die 'makes no sence...';
147 }
148  
149  
150 2 1;
151  
152  
153 __END__
« Transform/SAX/Filter.pm ↑ Summary Transform/using/XML/SAX.pm »