Safari/Response/Section.pm

filter: Statementstmt 57.1% 28 / 49 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.0% 8 / 10 Podpod 100% 1 / 1 totaltotal 52.1% 37 / 71 CC 5 SCAR 19.7
CC
5
Cov
48%
_init
20.0
new
6.0
BEGIN
1.0
CRAP 7.1
« Safari/Response/Book.pm ↑ Summary Safari/Response.pm »
1 package Net::Safari::Response::Section;
2  
3 =head1 NAME
4  
5 Net::Safari::Response::Section - Section node returned by Safari
6  
7 =head1 SYNOPSIS
8  
9 use Net::Safari::Response::Section;
10 my $book = Net::Safari::Response::Section->new(%book_ref);
11  
12 my @sections = $response->book->sections;
13  
14 print $section->title;
15  
16 =head1 DESCRIPTION
17  
18 See Net::Safari for general usage info.
19  
20 In most cases this object is created for you by Net::Safari::Response after a Net::Safari->search() call.
21  
22 =head1 ACCESSORS
23 The accessor descriptions are mostly pulled from the official spec:
24 http://safari.oreilly.com/affiliates/?p=response
25  
26 =head2 title()
27  
28 Section title.
29  
30 =head2 heading()
31  
32 Name of the section's heading, i.e. "Chapter 2"
33  
34 =head2 extract()
35  
36 Text preview of the area surrounding the match.
37  
38 =head2 search_term_matches()
39  
40 Terms that matched in this node. Corresponds to h1hit in the spec.
41  
42 =head2 preview()
43  
44 HTML preview of the requested section. Only available on by "id" matches.
45  
46 =head2 url()
47  
48 URL to this section on Safari.
49  
50 =head2 type()
51  
52 Section type. Not documented. Ex: "chapter." Not sure what other possibilities
53 are.
54  
55 =cut
56  
57  
58 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
59  
60 13 our $VERSION = 0.01;
61  
62 13 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 13 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 13 ▶use Class::Accessor;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 13 ▶use Class::Fields;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 13 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
67  
68 13 ▶use base qw(Class::Accessor Class::Fields);
Subroutine BEGIN: called CC=1 SCAR=0.0
69  
70 13 our @BASIC_FIELDS = qw(
71 url
72 title
73 heading
74 extract
75 search_term_matches
76 preview
77 type
78 );
79  
80 13 ▶use fields @BASIC_FIELDS;
Subroutine BEGIN: called CC=1 SCAR=0.0
81 13 Net::Safari::Response::Section->mk_accessors(@BASIC_FIELDS);
82  
83 =head1 METHODS
84  
85 =head2 new()
86  
87 $book = Net::Safari::Response::Section->new($ref);
88  
89 Takes a hash represenation of the XML returned by Safari. Normally this is
90 taken care of by Net::Safari::Response::Book.
91  
92 =cut
93  
94 sub new
95 0 ▶{
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
96 0 my ($class, %args) = @_;
97  
98 0 ▶ my $self = bless ({}, ref ($class) || $class);
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
99  
100 0 $self->_init(%args);
101  
102 0 return ($self);
103 }
104  
105 0 ▶sub _init {
Subroutine _init: not called CC=4 SCAR=30.0
106 0 my $self = shift;
107 0 my %args = @_;
108
109 #Title
110 0 $self->title($args{title});
111  
112 #Heading
113 0 $self->heading($args{heading});
114  
115 #Extract
116 #TODO - find out why content is an array
117 #TODO - interleave content and hlhit
118 0 ▶ if (ref $args{extract} eq "HASH")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{'extract'} eq 'HASH') { } 0 0 0
119 {
120 0 my $extract = "";
121 0 my $i;
122 0 ▶ for ($i = 0; $i < @{$args{extract}->{hlhit}}; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$args{"extract"}{"hlhit"};}) 0 0 0
123 {
124 $extract .= $args{extract}->{content}->[$i]
125 0 . $args{extract}->{hlhit}->[$i];
126 }
127 0 ▶ if ($args{extract}->{content}->[$i])
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"extract"}{"content"}[$i]) 0 0 0
128 {
129 0 $extract .= $args{extract}->{content}->[$i];
130 }
131  
132 0 $self->extract($extract);
133 }
134 else
135 {
136 0 $self->extract($args{extract});
137 }
138
139 #Preview
140 0 $self->preview($args{preview});
141  
142  
143 #URL
144 0 $self->url($args{url});
145  
146 #Type
147 0 $self->type($args{type});
148 }
149  
150 =head1 BUGS
151  
152 None yet.
153  
154 =head1 SUPPORT
155  
156 If you find a bug in the code or find that the code doesn't match Safari API, please send me a line.
157  
158 If the Safari API is down or has bugs, please contact Safari directly:
159 affiliates@safaribooksonline.com
160  
161 =head1 ACKNOWLEDGMENTS
162  
163 Adapted from the design of Net::Amazon by Mike Schilli.
164  
165 Some documentation based on the source Safari documentation:
166 http://safari.oreilly.com/affiliates/?p=web_services
167  
168 =head1 AUTHOR
169  
170 Tony Stubblebine
171 tonys@oreilly.com
172  
173 =head1 COPYRIGHT
174  
175 Copyright 2004 by Tony Stubblebine (tonys@oreilly.com)
176  
177 This program is free software; you can redistribute
178 it and/or modify it under the same terms as Perl itself.
179  
180 The full text of the license can be found in the
181 LICENSE file included with this module.
182  
183  
184 =head1 SEE ALSO
185  
186 perl(1).
187  
188 =cut
189  
190  
191  
192 13 1; #this line is important and will help the module return a true value
193 __END__
« Safari/Response/Book.pm ↑ Summary Safari/Response.pm »