blib/lib/Github/Score.pm

filter: Statementstmt 84.9% 45 / 53 Branchbran 87.5% 7 / 8 Conditioncond 85.7% 6 / 7 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 85.7% 12 / 14 Podpod 83.3% 5 / 6 totaltotal 84.7% 78 / 92 CC 9 SCAR 12.8
CC
9
Cov
85%
new
7.0
clear
6.0
scores
2.9
CRAP 3.6
↑ Summary
1 package Github::Score;
2 #ABSTRACT: Pull author contribution counts for github repos
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use LWP;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use Moose; # automatically turns on strict and warnings
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 has 'user' => (is => 'rw', );
16 1 has 'repo' => (is => 'rw', );
17 1 has 'timeout' => (is => 'rw', );
18 1 has 'api_version' => (is => 'rw', );
19  
20 0 ▶ sub clear {
Subroutine clear: not called CC=2 SCAR=17.9
Pod undocumented
21 0 my $self = shift;
22 0 $self->$_(undef) for qw(ua user json uri timeout);
23 }
24  
25  
26 1 our $VERSION = '0.001';
27 1 $VERSION = eval $VERSION;
28
29 8 ▶ sub new {
Subroutine new: called CC=7 SCAR=19.5
Pod documented
30 8 my $self = shift;
31 8 my @args = @_;
32
33 8 ▶ unshift @args, 'url' if @args % 2 && !ref( $args[0] );
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 and not ref $args[0] 5 3 8
Condition100%3/3
@args % 2 and not ref $args[0]
!ll&&!rl&&r
215
MC/DC100%2/2
@args % 2 and not ref $args[0]
@args % 2 not ref $args[0]
Truth table100%3/3
A and not(B)
A= @args % 2B= not ref $args[0]
ABresult
0X0
100
111
34
35 8 ▶ my %args = ref( $args[0] ) ? %{ $args[0] } : @args;
Branch: 1 branch
BranchTrueFalseTotal
ref $args[0] ? : 1 7 8
36 8 ▶ if ( exists $args{url} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"url"}) 5 3 8
37 5 ( $args{user}, $args{repo} ) = ( split /\//, delete $args{url} );
38 }
39
40 8 ▶ my $timeout = $args{timeout} || 10;
Condition100%2/2
$args{'timeout'} || 10
l!l
17
MC/DC100%1/1
$args{'timeout'} || 10
$args{'timeout'}
Truth table100%2/2
A
A= $args{'timeout'}
Aresult
11
00
41
42 bless {
43 user => $args{user},
44 repo => $args{repo},
45 timeout => $timeout,
46 8 ▶ api_version => ($args{api_version} || 'v2'),
Condition50%1/2
$args{'api_version'} || 'v2'
l!l
08
MC/DC0%0/1
$args{'api_version'} || 'v2'
$args{'api_version'}
Truth table50%1/2
A
A= $args{'api_version'}
Aresult
11
00
47 }, $self;
48 }
49
50 8 ▶ sub ua {
Subroutine ua: called CC=1 SCAR=0.0
Pod documented
51 8 LWP::UserAgent->new(
52 timeout => $_[0]->timeout,
53 agent => join ' ', ( __PACKAGE__, $VERSION )
54 );
55 }
56  
57  
58 8 ▶ sub uri {
Subroutine uri: called CC=1 SCAR=0.0
Pod documented
59 8 URI->new( sprintf( 'http://github.com/api/%s/json/repos/show/%s/%s/contributors',
60 $_[0]->api_version,$_[0]->user, $_[0]->repo )
61 );
62 }
63 0 ▶ sub json { JSON->new->allow_nonref }
Subroutine json: not called CC=1 SCAR=6.9
Pod documented
64
65 8 ▶ sub scores {
Subroutine scores: called CC=2 SCAR=10.5
Pod documented
66 8 my $self = shift;
67
68 8 my $response = $self->ua->request( HTTP::Request->new( GET => $self->uri->canonical ) );
69 8 ▶ return {} unless $response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_success 8 0 8
70
71 0 my %scores;
72 0 my $contributors = $self->json->decode( $response->content )->{contributors};
73
74 0 map { $scores{ $_->{login} } = $_->{contributions} } @$contributors;
75 0 return \%scores;
76 }
77
78 1 1;
79  
80  
81 =pod
82  
83 =head1 NAME
84  
85 Github::Score - Pull author contribution counts for github repos
86  
87 =head1 VERSION
88  
89 version 0.2.0
90  
91 =head1 AUTHOR
92  
93 justin.d.hunter@gmail.com
94  
95 =head1 COPYRIGHT AND LICENSE
96  
97 This software is copyright (c) 2011 by AHB.
98  
99 This is free software; you can redistribute it and/or modify it under
100 the same terms as the Perl 5 programming language system itself.
101  
102 =cut
103  
104  
105 __DATA__
↑ Summary