| 1 | package Github::Email; | ||||||||||||||||||||||||||||
| 2 | 1 | $Github::Email::VERSION = '1.1.0'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: Search and print particular Github user emails. | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use JSON; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use List::MoreUtils qw(uniq); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Email::Valid; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub get_emails { | ||||||||||||||||||||||||||
|
Subroutine
get_emails: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 0 | my $username = shift; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | my $user_agent = LWP::UserAgent->new; | |||||||||||||||||||||||||||
| 19 | 0 | my $get_json = | |||||||||||||||||||||||||||
| 20 | $user_agent->get("https://api.github.com/users/$username/events/public"); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | if ( $get_json->is_success ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 0 | my $raw_json = $get_json->decoded_content; | |||||||||||||||||||||||||||
| 24 | 0 | my $decoded_json = decode_json $raw_json; | |||||||||||||||||||||||||||
| 25 | 0 | my @push_events = grep { $_->{type} eq 'PushEvent' } @{$decoded_json}; | |||||||||||||||||||||||||||
| 26 | 0 | my @commits = map { @{$_->{payload}->{commits}} } @push_events; | |||||||||||||||||||||||||||
| 27 | 0 | my @addresses = map { $_->{author}->{email} } @commits; | |||||||||||||||||||||||||||
| 28 | 0 | my @unique_addresses = uniq @addresses; | |||||||||||||||||||||||||||
| 29 | 0 | my @retrieved_addresses; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | for my $address (@unique_addresses) { | |||||||||||||||||||||||||||
| 32 | 0 | ▶ | if ( $address ne 'git@github.com' && Email::Valid->address($address) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$address ne "git\@github.com" and "Email::Valid"->address($address)
MC/DC0%0/2
$address ne "git\@github.com" and "Email::Valid"->address($address)
$address ne "git\@github.com"
"Email::Valid"->address($address)
Truth table0%0/3
A and B
A= $address ne "git\@github.com"B= "Email::Valid"->address($address)
| |||||||||||||||||||||||||||||
| 33 | 0 | push( @retrieved_addresses, $address ); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | return @retrieved_addresses; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | else { | ||||||||||||||||||||||||||||
| 41 | 0 | confess("User doesn't exist"); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1 | 1; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | __END__ | ||||||||||||||||||||||||||||