Pachube/Feed.pm

filter: Statementstmt 100% 56 / 56 Branchbran 100% 12 / 12 Conditioncond 100% 8 / 8 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 23 / 23 Podpod 100% 16 / 16 totaltotal 100% 119 / 119 CC 11 SCAR 5.8
CC
11
Cov
100%
data_tags
4.0
new
2.0
get
2.0
CRAP 1.8
« Pachube.pm ↑ Summary
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Net::Pachube::Feed;
4 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 $Net::Pachube::Feed::VERSION = '1.102900';
6 }
7  
8 # ABSTRACT: Perl extension for manipulating pachube.com feeds
9  
10  
11 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use base qw/Class::Accessor::Fast/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 __PACKAGE__->mk_accessors(qw/id pachube eeml/);
17  
18  
19 6 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
20 6 my $pkg = shift;
21 6 my %p = @_;
22 6 my $self = $pkg->SUPER::new(\%p);
23 6 ▶ $p{fetch} ? $self->get() : $self;
Branch: 1 branch
BranchTrueFalseTotal
$p{'fetch'} ? : 5 1 6
24 }
25  
26  
27 6 ▶sub get {
Subroutine get: called CC=2 SCAR=6.9
Pod documented
28 6 my ($self) = @_;
29 6 my $pachube = $self->pachube;
30 6 my $url = $pachube->url.'/'.$self->id.'.xml';
31 6 ▶ my $resp = $pachube->_request(method => 'GET', url => $url) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $resp = $pachube->_request("method", "GET", "url", $url) or return 4 1 5
32 4 $self->{eeml} = $resp->content;
33 $self->{_hash} = XMLin($self->{eeml},
34 4 KeyAttr => [qw/id/],
35 ForceArray => [qw/data/]);
36 4 return $self;
37 }
38  
39  
40 1 ▶sub title {
Subroutine title: called CC=1 SCAR=0.0
Pod documented
41 1 $_[0]->{_hash}->{environment}->{title};
42 }
43  
44  
45 1 ▶sub description {
Subroutine description: called CC=1 SCAR=0.0
Pod documented
46 1 $_[0]->{_hash}->{environment}->{description};
47 }
48  
49  
50 3 ▶sub feed_id {
Subroutine feed_id: called CC=1 SCAR=0.0
Pod documented
51 3 $_[0]->{_hash}->{environment}->{id};
52 }
53  
54  
55 1 ▶sub status {
Subroutine status: called CC=1 SCAR=0.0
Pod documented
56 1 $_[0]->{_hash}->{environment}->{status};
57 }
58  
59  
60 3 ▶sub feed_url {
Subroutine feed_url: called CC=1 SCAR=0.0
Pod documented
61 3 $_[0]->{_hash}->{environment}->{feed};
62 }
63  
64  
65 1 ▶sub creator {
Subroutine creator: called CC=1 SCAR=0.0
Pod documented
66 1 $_[0]->{_hash}->{environment}->{creator};
67 }
68  
69  
70 2 ▶sub location {
Subroutine location: called CC=2 SCAR=6.9
Pod documented
71 defined $_[1] ? $_[0]->{_hash}->{environment}->{location}->{$_[1]} :
72 2 ▶ $_[0]->{_hash}->{environment}->{location};
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 1 1 2
73 }
74  
75  
76 2 ▶sub number_of_streams {
Subroutine number_of_streams: called CC=1 SCAR=0.0
Pod documented
77 2 scalar keys %{$_[0]->{_hash}->{environment}->{data}}
78 }
79  
80  
81 2 ▶sub data_value {
Subroutine data_value: called CC=2 SCAR=6.9
Pod documented
82 2 ▶ $_[0]->{_hash}->{environment}->{data}->{$_[1]||0}->{value}->{content};
Condition100%2/2
$_[1] || 0
l!l
11
MC/DC100%1/1
$_[1] || 0
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
83 }
84  
85  
86 2 ▶sub data_min {
Subroutine data_min: called CC=2 SCAR=6.9
Pod documented
87 2 ▶ $_[0]->{_hash}->{environment}->{data}->{$_[1]||0}->{value}->{minValue};
Condition100%2/2
$_[1] || 0
l!l
11
MC/DC100%1/1
$_[1] || 0
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
88 }
89  
90  
91 2 ▶sub data_max {
Subroutine data_max: called CC=2 SCAR=6.9
Pod documented
92 2 ▶ $_[0]->{_hash}->{environment}->{data}->{$_[1]||0}->{value}->{maxValue};
Condition100%2/2
$_[1] || 0
l!l
11
MC/DC100%1/1
$_[1] || 0
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
93 }
94  
95  
96 3 ▶sub data_tags {
Subroutine data_tags: called CC=4 SCAR=13.9
Pod documented
97 3 ▶ my $tags = $_[0]->{_hash}->{environment}->{data}->{$_[1]||0}->{tag} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $tags = $_[0]{"_hash"}{"environment"}{"data"}{$_[1] or 0}{"tag"} or return 2 1 3
Condition100%2/2
$_[1] || 0
l!l
21
MC/DC100%1/1
$_[1] || 0
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
98 2 ▶ ref $tags ? @$tags : $tags
Branch: 1 branch
BranchTrueFalseTotal
ref $tags ? : 1 1 2
99 }
100  
101  
102 2 ▶sub update {
Subroutine update: called CC=2 SCAR=6.9
Pod documented
103 2 my ($self) = shift;
104 2 my %p = @_;
105 2 my $pachube = $self->pachube;
106 2 my $url = $pachube->url.'/'.$self->id;
107 2 ▶ my $data = ref $p{data} ? $p{data} : [$p{data}];
Branch: 1 branch
BranchTrueFalseTotal
ref $p{'data'} ? : 1 1 2
108 2 $pachube->_request(method => 'PUT', url => $url.'.csv',
109 content => (join ',', @$data));
110 }
111  
112  
113 1 ▶sub delete {
Subroutine delete: called CC=1 SCAR=0.0
Pod documented
114 1 my $self = shift;
115 1 my $pachube = $self->pachube;
116 1 my $url = $pachube->url.'/'.$self->id;
117 1 delete $self->{eeml};
118 1 $pachube->_request(method => 'DELETE', url => $url);
119 }
120  
121 2 1;
122  
123  
124 =pod
125  
126 =head1 NAME
127  
128 Net::Pachube::Feed - Perl extension for manipulating pachube.com feeds
129  
130 =head1 VERSION
131  
132 version 1.102900
133  
134 =head1 SYNOPSIS
135  
136 # normally instantiated using:
137  
138 use Net::Pachube;
139 my $pachube = Net::Pachube->new();
140 my $feed = $pachube->feed($feed_id);
141 print $feed->title, " ", $feed->status, "\n";
142 foreach my $i (0..$feed->number_of_streams-1) {
143 print "Stream ", $i, " value: ", $feed->data_value($i), "\n";
144 foreach my $tag ($feed->data_tags($i)) {
145 print " Tag: ", $tag, "\n";
146 }
147 }
148  
149 # update several streams at once
150 $feed->update(data => [0,1,2,3,4]);
151  
152 # update one stream
153 $feed->update(data => 99);
154  
155 =head1 DESCRIPTION
156  
157 This module encapsulates a www.pachube.com feed.
158  
159 =head1 METHODS
160  
161 =head2 C<new( %parameters )>
162  
163 The constructor creates a new L<Net:Pachube::Feed> object. This
164 method is generally only called by the L<Net::Pachube> request
165 methods. The constructor takes a parameter hash as arguments. Valid
166 parameters in the hash are:
167  
168 =over
169  
170 =item id
171  
172 The id of the feed.
173  
174 =item pachube
175  
176 The L<Net::Pachube> connection object.
177  
178 =back
179  
180 =head2 C<get( )>
181  
182 This method refreshes the contents of the feed by sending a C<GET>
183 request to the server. It is automatically called when the feed
184 is created but may be called again to refresh the feed data.
185  
186 =head2 C<eeml( )>
187  
188 This method returns the L<EEML> of the feed.
189  
190 =head2 C<title( )>
191  
192 This method returns the title of the feed from the L<EEML> if the
193 request was successful.
194  
195 =head2 C<description( )>
196  
197 This method returns the description of the feed from the L<EEML> if the
198 request was successful.
199  
200 =head2 C<feed_id( )>
201  
202 This method returns the id of the feed from the L<EEML> if the request
203 was successful. It should always be equal to C<< $self->id >> which is
204 used to request the feed data.
205  
206 =head2 C<status( )>
207  
208 This method returns the status of the feed from the L<EEML> if the request
209 was successful.
210  
211 =head2 C<feed_url( )>
212  
213 This method returns the URL for the feed from the L<EEML> if the
214 request was successful.
215  
216 =head2 C<creator( )>
217  
218 This method returns the creator value from the L<EEML> if the request
219 was successful.
220  
221 =head2 C<location( [ $key ] )>
222  
223 This method returns the location information from the L<EEML> if the
224 request was successful. If the optional C<key> parameter is not
225 supplied then a hash reference will be returned. If the optional
226 C<key> parameter is supplied then the value for that key from the hash
227 is returned.
228  
229 =head2 C<number_of_streams( )>
230  
231 This method returns the number of data streams present in the feed.
232  
233 =head2 C<data_value( [ $index ] )>
234  
235 This method returns the value from the data stream from the L<EEML>
236 if the request was successful. If the optional zero-based C<index>
237 parameter is not provided, it is assumed to be zero.
238  
239 =head2 C<data_min( [ $index ] )>
240  
241 This method returns the minimum value for the data stream from the
242 L<EEML> if the request was successful. It may be undefined. If the
243 optional zero-based C<index> parameter is not provided, it is assumed
244 to be zero.
245  
246 =head2 C<data_max( [ $index ] )>
247  
248 This method returns the maximum value for the data stream from the
249 L<EEML> if the request was successful. It may be undefined. If the
250 optional zero-based C<index> parameter is not provided, it is assumed
251 to be zero.
252  
253 =head2 C<data_tags( [ $index ] )>
254  
255 This method returns the tag value for the data stream from the L<EEML>
256 if the request was successful. It may be undefined or a list of tags.
257 If the optional zero-based C<index> parameter is not provided, it is
258 assumed to be zero.
259  
260 =head2 C<<update( data => \@data_values )>>
261  
262 This method performs a C<PUT> request in order to update a feed.
263 It returns true on success or undef otherwise.
264  
265 =head2 C<delete( )>
266  
267 This method sends a C<DELETE> request to the server to remove
268 it from the server. It returns true if successful or undef
269 otherwise.
270  
271 =head1 SEE ALSO
272  
273 Pachube web site: http://www.pachube.com/
274  
275 =head1 AUTHOR
276  
277 Mark Hindess <soft-pachube@temporalanomaly.com>
278  
279 =head1 COPYRIGHT AND LICENSE
280  
281 This software is copyright (c) 2010 by Mark Hindess.
282  
283 This is free software; you can redistribute it and/or modify it under
284 the same terms as the Perl 5 programming language system itself.
285  
286 =cut
287  
288  
289 __END__
« Pachube.pm ↑ Summary