File Coverage

blib/lib/App/Github/Email.pm
Criterion Covered Total %
statement 18 39 46.1
branch 0 4 0.0
condition 0 3 0.0
subroutine 6 7 85.7
pod 1 1 100.0
total 25 54 46.3


line stmt bran cond sub pod time code
1             package App::Github::Email;
2             $App::Github::Email::VERSION = '0.3.2';
3             # ABSTRACT: Search and print particular Github user emails.
4              
5 1     1   119052 use strict;
  1         4  
  1         30  
6 1     1   5 use warnings;
  1         3  
  1         30  
7              
8 1     1   8 use Carp qw(confess);
  1         1  
  1         62  
9 1     1   8 use JSON;
  1         3  
  1         8  
10 1     1   157 use LWP::UserAgent;
  1         8  
  1         35  
11 1     1   6 use List::MoreUtils qw(uniq);
  1         2  
  1         6  
12              
13              
14             sub get_user {
15 0     0 1   my $username = shift;
16              
17 0           my $ua = LWP::UserAgent->new;
18 0           my $get_json =
19             $ua->get("https://api.github.com/users/$username/events/public");
20              
21 0 0         if ( $get_json->is_success ) {
22 0           my $raw_json = $get_json->decoded_content;
23 0           my $dec_json = decode_json $raw_json;
24 0           my @push_events = grep { $_->{type} eq 'PushEvent' } @{$dec_json};
  0            
  0            
25 0           my @commits = map { @{$_->{payload}->{commits}} } @push_events;
  0            
  0            
26 0           my @addresses = map { $_->{author}->{email} } @commits;
  0            
27 0           my @unique_addr = uniq @addresses;
28 0           my @retrieved_addrs;
29              
30 0           for my $address (@unique_addr) {
31 0 0 0       if ( $address ne 'git@github.com' and not $address =~ /^":"/g ) {
32 0           push( @retrieved_addrs, $address );
33             }
34             }
35              
36 0           return @retrieved_addrs;
37             }
38              
39             else {
40 0           confess("User is not exist.");
41             }
42             }
43              
44             1;
45              
46             __END__