| 1 | package Net::Google::Code::Role::Authentication; | ||||||||||
| 2 | 11 | ▶ | use Any::Moose 'Role'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | 11 | with 'Net::Google::Code::Role::Fetchable'; | |||||||||
| 5 | |||||||||||
| 6 | 11 | has 'email' => ( | |||||||||
| 7 | isa => 'Str', | ||||||||||
| 8 | is => 'rw', | ||||||||||
| 9 | ); | ||||||||||
| 10 | |||||||||||
| 11 | 11 | has 'password' => ( | |||||||||
| 12 | isa => 'Str', | ||||||||||
| 13 | is => 'rw', | ||||||||||
| 14 | ); | ||||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | sub sign_in { | ||||||||
|
Subroutine
sign_in: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 17 | 0 | my $self = shift; | |||||||||
| 18 | 0 | ▶ | return 1 if $self->signed_in; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 0 | ▶ | die "need password" unless $self->password; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | |||||||||||
| 21 | 0 | $self->mech->get('https://www.google.com/accounts/Login'); | |||||||||
| 22 | |||||||||||
| 23 | 0 | $self->mech->submit_form( | |||||||||
| 24 | with_fields => { | ||||||||||
| 25 | Email => $self->email, | ||||||||||
| 26 | Passwd => $self->password, | ||||||||||
| 27 | }, | ||||||||||
| 28 | ); | ||||||||||
| 29 | |||||||||||
| 30 | 0 | ▶ | die 'sign in failed to google code' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | unless $self->signed_in; | ||||||||||
| 32 | |||||||||||
| 33 | 0 | return 1; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 0 | ▶ | sub sign_out { | ||||||||
|
Subroutine
sign_out: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 37 | 0 | my $self = shift; | |||||||||
| 38 | 0 | $self->mech->get('https://www.google.com/accounts/Logout'); | |||||||||
| 39 | |||||||||||
| 40 | 0 | ▶ | die 'sign out failed to google code' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | unless $self->signed_in; | ||||||||||
| 42 | |||||||||||
| 43 | 0 | return 1; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 0 | ▶ | sub signed_in { | ||||||||
|
Subroutine
signed_in: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 47 | 0 | my $self = shift; | |||||||||
| 48 | |||||||||||
| 49 | 0 | my $html = $self->mech->content; | |||||||||
| 50 | 0 | ▶ | return unless $html; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | # remove lines of head, style and script | ||||||||||
| 52 | 0 | $html =~ s!<head>.*?</head>!!sg; | |||||||||
| 53 | 0 | $html =~ s!<style.*?</style>!!sg; | |||||||||
| 54 | 0 | $html =~ s!<script.*?</script>!!sg; | |||||||||
| 55 | |||||||||||
| 56 | 0 | my @lines = split /\n/, $html; | |||||||||
| 57 | 0 | my $signed_in; | |||||||||
| 58 | 0 | my $line = 0; | |||||||||
| 59 | |||||||||||
| 60 | # only check the first 30 lines or so in case user input of 'sign out' | ||||||||||
| 61 | # exists below | ||||||||||
| 62 | 0 | for ( @lines ) { | |||||||||
| 63 | 0 | ▶ | $signed_in = 1 if /sign out/i; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 0 | $line++; | |||||||||
| 65 | 0 | ▶ | last if $line == 30; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | } | ||||||||||
| 67 | 0 | return $signed_in; | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 11 | ▶ | no Any::Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 71 | |||||||||||
| 72 | 11 | 1; | |||||||||
| 73 | |||||||||||
| 74 | __END__ | ||||||||||