File Coverage

blib/lib/WWW/Ohloh/API/Role/Fetchable.pm
Criterion Covered Total %
statement 34 43 79.0
branch 1 2 50.0
condition 0 6 0.0
subroutine 10 11 90.9
pod 0 3 0.0
total 45 65 69.2


line stmt bran cond sub pod time code
1             package WWW::Ohloh::API::Role::Fetchable;
2             our $AUTHORITY = 'cpan:YANICK';
3              
4 38     38   184944 use strict;
  38         1179  
  38         1501  
5 38     38   1247 use warnings;
  38         920  
  38         2091  
6              
7 38     38   934 use Object::InsideOut;
  38         46332  
  38         827  
8              
9 38     38   4006 use Carp;
  38         105  
  38         3115  
10 38     38   6006 use Params::Validate qw/ validate_with validate /;
  38         105924  
  38         2867  
11 38     38   3899 use URI;
  38         36306  
  38         14873  
12              
13             our $VERSION = '1.0_1';
14              
15             #<<<
16             my @request_url_of : Field
17             : Arg(Name => 'request_url', Preproc => \&WWW::Ohloh::API::Role::Fetchable::process_url)
18             : Get(request_url)
19             : Type(URI);
20             my @ohloh_of : Field
21             : Arg(ohloh)
22             : Set(set_ohloh)
23             : Get(ohloh);
24             #>>>
25             sub process_url {
26 17     17 0 345866 my $value = $_[4];
27              
28 17         192 return URI->new($value);
29             }
30              
31             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32              
33             sub fetch {
34 6     6 0 30 my ( $class, @args ) = @_;
35              
36 6 50       25 if ( ref $class ) {
37 0         0 push @args, ohloh => $class->ohloh;
38 0         0 $class = ref $class;
39             }
40              
41 6         194 my %param = validate_with(
42             params => \@args,
43             spec => { ohloh => 1 },
44             allow_extra => 1,
45             );
46              
47 6         45 my $ohloh = $param{ohloh};
48              
49 6         41 my ($url) = $class->generate_query_url(%param);
50              
51 6         125 my ( undef, $xml ) = $ohloh->_query_server($url);
52              
53 6         84 my ($node) = $xml->findnodes( $class->element_name );
54              
55 6         216 return $class->new( ohloh => $ohloh, xml => $node, request_url => $url );
56             }
57              
58             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59              
60             sub generate_query_url : Chained(bottom up) {
61 0     0 0   my ( $self, $url, %args ) = @_;
62              
63 0           my $ohloh = $args{ohloh};
64 0           delete $args{ohloh};
65 0   0       $args{api_key} ||= $ohloh->get_api_key;
66 0   0       $args{v} ||= $ohloh->get_api_version;
67              
68 38     38   342 no warnings qw/ uninitialized /;
  38         86  
  38         6249  
69              
70             return $WWW::Ohloh::API::OHLOH_URL . $url . '?' . join '&',
71 0           map { $_ . '=' . $args{$_} } reverse sort keys %args;
  0            
72 38     38   354 }
  38         125  
  38         444  
73              
74             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75              
76             'end of WWW::Ohloh::API::Role::Fetchable';
77              
78             __END__