| 1 | package Net::Google::Code::Role::Predefined; | ||||||||||||||||||||
| 2 | 10 | ▶ | use Any::Moose 'Role'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 10 | ▶ | use Params::Validate ':all'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 10 | ▶ | use JSON; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 10 | with 'Net::Google::Code::Role::Fetchable'; | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 10 | has 'predefined_status' => ( | |||||||||||||||||||
| 8 | isa => 'HashRef', | ||||||||||||||||||||
| 9 | is => 'rw', | ||||||||||||||||||||
| 10 | ); | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 10 | has 'predefined_labels' => ( | |||||||||||||||||||
| 13 | isa => 'ArrayRef', | ||||||||||||||||||||
| 14 | is => 'rw', | ||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 10 | ▶ | no Any::Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 1 | ▶ | sub load_predefined { | ||||||||||||||||||
|
Subroutine
load_predefined: called CC=10 SCAR=23.9
Pod
documented
| |||||||||||||||||||||
| 20 | 1 | my $self = shift; | |||||||||||||||||||
| 21 | 1 | ▶ | my $class = ref $self || $self; | ||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||
| 22 | 1 | my $last_name; | |||||||||||||||||||
| 23 | 1 | ▶ | $last_name = lc $1 if $class =~ /::(\w+)$/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 1 | ▶ | return unless $self->signed_in; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | 1 | my $base_url = $self->base_url; | |||||||||||||||||||
| 27 | 1 | my $content = $self->fetch($self->base_url); | |||||||||||||||||||
| 28 | 1 | ▶ | if ( $content =~ /codesite_token\s*=\s*"(\w+)"/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | 1 | my $token = $1; | |||||||||||||||||||
| 30 | 1 | my $mech = $self->mech; | |||||||||||||||||||
| 31 | # I tried to use $mech->post( $url, token => $token ) | ||||||||||||||||||||
| 32 | # but without luck :( | ||||||||||||||||||||
| 33 | 1 | $mech->update_html(<<"EOF"); | |||||||||||||||||||
| 34 | <form action="${base_url}feeds/${last_name}OptionsJSON" | ||||||||||||||||||||
| 35 | method="POST" > | ||||||||||||||||||||
| 36 | <input type="text" name="token" value="$token" /> | ||||||||||||||||||||
| 37 | <input type="submit" value="submit" /> | ||||||||||||||||||||
| 38 | </form> | ||||||||||||||||||||
| 39 | EOF | ||||||||||||||||||||
| 40 | 1 | $mech->submit_form( form_number => 1 ); | |||||||||||||||||||
| 41 | 1 | ▶ | die "failed to post to OptionsJSON page" unless $mech->success; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 1 | my $js = $mech->content; | |||||||||||||||||||
| 44 | 1 | my $object = from_json $js; | |||||||||||||||||||
| 45 | 1 | ▶ | return unless $object; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 1 | $self->predefined_status( { open => [], closed => [] } ); | |||||||||||||||||||
| 48 | 1 | for my $type (qw/open closed/) { | |||||||||||||||||||
| 49 | 2 | for ( @{ $object->{$type} } ) { | |||||||||||||||||||
| 50 | 9 | push @{ $self->predefined_status->{$type} }, $_->{name}; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 1 | $self->predefined_labels( [] ); | |||||||||||||||||||
| 55 | 1 | for ( @{ $object->{labels} } ) { | |||||||||||||||||||
| 56 | 23 | push @{ $self->predefined_labels }, $_->{name}; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 1 | return 1; | |||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | else { | ||||||||||||||||||||
| 62 | 0 | warn "can't get user token"; | |||||||||||||||||||
| 63 | 0 | return; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 10 | 1; | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | __END__ | ||||||||||||||||||||