blib/lib/WWW/Mechanize/Meta.pm

filter: Statementstmt 85.7% 54 / 63 Branchbran 60.0% 6 / 10 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 92.3% 12 / 13 Podpod 100% 6 / 6 totaltotal 82.3% 84 / 102 CC 10 SCAR 10.2
CC
10
Cov
81%
_parse_head
6.0
rss
4.0
link
4.0
CRAP 2.8
↑ Summary
1 package WWW::Mechanize::Meta;
2  
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use HTTP::Headers;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use HTML::HeadParser;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 ▶use base 'WWW::Mechanize';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 WWW::Mechanize::Meta - Adds HEAD tag parsing to WWW::Mechanize
14  
15 =head1 VERSION
16  
17 Version 0.07
18  
19 =cut
20  
21 5 our $VERSION = '0.07';
22  
23 =head1 SYNOPSIS
24  
25 use WWW::Mechanize::Meta;
26  
27 my $mech = WWW::Mechanize::Meta->new();
28 my @css=$mech->link('stylesheet');
29 foreach (@css){
30 print "$_->{href}\n";
31 }
32
33  
34 =head1 METHODS
35  
36 =head2 link( [$type] )
37  
38 Returns link tag with attribure rel = $type. If no attribute $type given, returns all link tags.
39  
40 =cut
41  
42 3 ▶sub link {
Subroutine link: called CC=4 SCAR=13.9
Pod documented
43 3 my $self = shift;
44 3 my $type = shift;
45 3 my @links;
46 3 foreach my $link ( $self->{head}->header('link') ) {
47  
48 21 my @params = split '; ', $link;
49 21 my ($src) = ( ( shift @params ) =~ m/\<(.*)\>/ );
50 21 my %params = map { m/(.*)=\"([^\"]*)\"/ } @params;
51 21 $params{href} = $src;
52 21 ▶ push @links, \%params if !$type || $params{rel} eq $type;
Branch: 1 branch
BranchTrueFalseTotal
if not $type or $params{"rel"} eq $type 4 17 21
Condition66%2/3
not $type or $params{"rel"} eq $type
l!l&&r!l&&!r
0417
MC/DC50%1/2
not $type or $params{"rel"} eq $type
not $type $params{"rel"} eq $type
Truth table66%2/3
not(A) or B
A= not $typeB= $params{"rel"} eq $type
ABresult
1X1
011
000
53 }
54 3 return @links;
55  
56 }
57  
58 =head2 rss
59  
60 Returns all rss objects for this page
61  
62 =cut
63  
64 2 ▶sub rss {
Subroutine rss: called CC=4 SCAR=13.9
Pod documented
65 2 my $self = shift;
66 2 my @links = $self->link('alternate');
67 2 my @news;
68 2 foreach (@links) {
69 push @news, $_
70 if $_->{type} eq 'application/rss+xml'
71 3 ▶ or $_->{type} eq 'application/atom+xml';
Branch: 1 branch
BranchTrueFalseTotal
if $_->{"type"} eq "application/rss+xml" or $_->{"type"} eq "application/atom+xml" 2 1 3
Condition66%2/3
$_->{"type"} eq "application/rss+xml" or $_->{"type"} eq "application/atom+xml"
l!l&&r!l&&!r
201
MC/DC50%1/2
$_->{"type"} eq "application/rss+xml" or $_->{"type"} eq "application/atom+xml"
$_->{"type"} eq "application/rss+xml" $_->{"type"} eq "application/atom+xml"
Truth table66%2/3
A or B
A= $_->{"type"} eq "application/rss+xml"B= $_->{"type"} eq "application/atom+xml"
ABresult
1X1
011
000
72 }
73 2 return @news;
74  
75 }
76  
77 =head2 headtag
78  
79 Returns raw header object
80  
81 =cut
82  
83 1 ▶sub headtag {
Subroutine headtag: called CC=1 SCAR=0.0
Pod documented
84 1 my $self = shift;
85 1 return $self->{head};
86 }
87  
88 =head1 INTERNAL METHODS
89  
90 =head2 new
91  
92 =cut
93  
94 3 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
95 3 my $class = shift;
96 3 my $self = $class->SUPER::new(@_);
97 3 $self->{headparser} = HTML::HeadParser->new();
98 3 return $self;
99 }
100  
101 =head2 title
102  
103 =cut
104  
105 1 ▶sub title {
Subroutine title: called CC=2 SCAR=9.2
Pod documented
106 1 my $self = shift;
107 1 ▶ return unless $self->is_html;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_html 1 0 1
108 0 my $title = $self->{head}->header('Title');
109 0 return $title;
110 }
111  
112 =head2 update_html
113  
114 =cut
115  
116 7 ▶sub update_html {
Subroutine update_html: called CC=2 SCAR=7.2
Pod documented
117 7 my $self = shift;
118 7 my $html = shift;
119 7 $self->SUPER::update_html($html);
120  
121 # warn $html;
122 7 ▶ if ( $self->is_html ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_html) { } 7 0 7
123 7 utf8::decode($html);
124 7 $self->{headparser}{'header'} = HTTP::Headers->new();
125 7 $self->{headparser}->parse($html);
126 7 $self->{head} = $self->{headparser}->header;
127 }
128 else {
129 0 $self->{head} = undef;
130 0 $self->{link} = undef;
131 }
132 7 return;
133 }
134  
135 =head2 _parse_head
136  
137 =cut
138  
139 0 ▶sub _parse_head {
Subroutine _parse_head: not called CC=2 SCAR=17.9
140 0 my $self = shift;
141 0 ▶ return unless $self->is_html;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_html 0 0 0
142 0 require HTML::HeadParser;
143 0 my $p = HTML::HeadParser->new;
144 0 $p->parse( $self->content );
145 }
146  
147 =head1 AUTHOR
148  
149 Andrey Kostenko, C<< <andrey@kostenko.name> >>
150  
151 =head1 BUGS
152  
153 Please report any bugs or feature requests to
154 C<bug-www-mechanize-meta at rt.cpan.org>, or through the web interface at
155 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Mechanize-Meta>.
156 I will be notified, and then you'll automatically be notified of progress on
157 your bug as I make changes.
158  
159 =head1 SUPPORT
160  
161 You can find documentation for this module with the perldoc command.
162  
163 perldoc WWW::Mechanize::Meta
164  
165 You can also look for information at:
166  
167 =over 4
168  
169 =item * AnnoCPAN: Annotated CPAN documentation
170  
171 L<http://annocpan.org/dist/WWW-Mechanize-Meta>
172  
173 =item * CPAN Ratings
174  
175 L<http://cpanratings.perl.org/d/WWW-Mechanize-Meta>
176  
177 =item * RT: CPAN's request tracker
178  
179 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Mechanize-Meta>
180  
181 =item * Search CPAN
182  
183 L<http://search.cpan.org/dist/WWW-Mechanize-Meta>
184  
185 =back
186  
187 =head1 ACKNOWLEDGEMENTS
188  
189 =head1 LICENSE
190  
191 Copyright 2007 Andrey Kostenko, all rights reserved.
192  
193 This program is free software; you can redistribute it and/or modify it
194 under the same terms as Perl itself.
195  
196 =cut
197  
198 5 1; # End of WWW::Mechanize::Meta
↑ Summary