blib/lib/WWW/Stickam/API.pm

filter: Statementstmt 77.2% 34 / 44 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 72.7% 8 / 11 Podpod 100% 4 / 4 totaltotal 76.1% 48 / 63 CC 3 SCAR 5.6
CC
3
Cov
75%
call
3.2
get
2.0
get_XML
2.0
CRAP 1.7
« lib/WWW/Stickam/API/Base.pm ↑ Summary lib/WWW/Stickam/API/Media/Information.pm »
1 package WWW::Stickam::API;
2  
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use base qw/Class::Accessor::Fast/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use UNIVERSAL::require;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use JSON::XS ;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use Time::HiRes;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 10 our $VERSION = '0.02';
12  
13 10 __PACKAGE__->mk_accessors(qw/data content error tv_interval/);
14  
15 13 ▶sub call {
Subroutine call: called CC=3 SCAR=11.7
Pod documented
16 13 my ( $s , $pkg , $args ) = @_;
17 13 my $t0 = [ Time::HiRes::gettimeofday() ];
18 13 $pkg =~ s/\//::/g;
19 13 $pkg = 'WWW::Stickam::API::' . $pkg ;
20 13 ▶ $pkg->require or die "The API call[$pkg] is not available...[$@]";
Branch: 1 branch
BranchTrueFalseTotal
$pkg->require or die "The API call[$pkg] is not available...[$@]" 13 0 13
21  
22 13 my $api = $pkg->new();
23  
24 13 ▶ if( $api->call( $args ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($api->call($args)) { } 0 13 13
25 0 $s->{content} = $api->content;
26 0 $s->{tv_interval} = Time::HiRes::tv_interval( $t0 );
27 0 return 1;
28 }
29 else {
30 13 $s->{error} = $api->error;
31 13 $s->{tv_interval} = Time::HiRes::tv_interval( $t0 );
32 13 return ;
33 }
34 }
35  
36 0 ▶sub get {
Subroutine get: not called CC=1 SCAR=6.9
Pod documented
37 0 my $s = shift;
38 0 return XMLin( $s->{content} );
39 }
40  
41 0 ▶sub get_XML {
Subroutine get_XML: not called CC=1 SCAR=6.9
Pod documented
42 0 my $s = shift;
43 0 return $s->{content};
44 }
45  
46 0 ▶sub get_JSON {
Subroutine get_JSON: not called CC=1 SCAR=6.9
Pod documented
47 0 my $s = shift;
48 0 my $data = $s->get();
49 0 return JSON::XS->new->utf8->pretty(1)->encode( $data );;
50 }
51  
52 10 1;
53  
54 =head1 NAME
55  
56 WWW::Stickam::API - Perl implementation of Stickam API
57  
58 =head1 SYNOPSYS
59  
60 my $api = WWW::Stickam::API->new();
61 if( $api->call('User/Profile' , { user_name => 'stickam' } ) ) {
62 print Dumper $api->get();
63 print $api->get_XML();
64 print $api->get_JSON();
65 }
66 else {
67 print $api->error ;
68 }
69  
70 =head1 DESCRIPTION
71  
72 Perl implementation of Stickam API. See http://labs.stickam.jp/api/
73  
74 =head1 METHOD
75  
76 =head2 new
77  
78 =head2 call
79  
80 This method call stickam API , take API name and parameters.
81 Return true for success , false for fail.
82  
83 =head2 get
84  
85 get result in hash array format.
86  
87 =head2 get_XML
88  
89 get result in XML
90  
91 =head2 get_JSON
92  
93 get result in JSON
94  
95 =head2 error
96  
97 get error message
98  
99 =head2 tv_interval
100  
101 get tv_interval. SEE L<Time::HiRes>
102  
103 =head2 SEE ALSO
104  
105 L<WWW::Stickam::API::User::Audio>
106  
107 L<WWW::Stickam::API::User::Image>
108  
109 L<WWW::Stickam::API::User::Profile>
110  
111 L<WWW::Stickam::API::User::Video>
112  
113 L<WWW::Stickam::API::Media::Information>
114  
115 L<WWW::Stickam::API::Search::Media>
116  
117 L<WWW::Stickam::API::Search::User>
118  
119 =head1 AUTHOR
120  
121 Tomohiro Teranishi <tomohiro.teranishi@gmail.com>
122  
123 =cut
124  
125  
« lib/WWW/Stickam/API/Base.pm ↑ Summary lib/WWW/Stickam/API/Media/Information.pm »