blib/lib/Net/Google/Code/Role/Predefined.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 40 | 42 | 95.2 |
branch | 5 | 10 | 50.0 |
condition | 1 | 3 | 33.3 |
subroutine | 5 | 5 | 100.0 |
pod | 1 | 1 | 100.0 |
total | 52 | 61 | 85.2 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package Net::Google::Code::Role::Predefined; | ||||||
2 | 10 | 10 | 7550 | use Any::Moose 'Role'; | |||
10 | 61 | ||||||
10 | 74 | ||||||
3 | 10 | 10 | 4697 | use Params::Validate ':all'; | |||
10 | 22 | ||||||
10 | 2158 | ||||||
4 | 10 | 10 | 6719 | use JSON; | |||
10 | 98844 | ||||||
10 | 84 | ||||||
5 | with 'Net::Google::Code::Role::Fetchable'; | ||||||
6 | |||||||
7 | has 'predefined_status' => ( | ||||||
8 | isa => 'HashRef', | ||||||
9 | is => 'rw', | ||||||
10 | ); | ||||||
11 | |||||||
12 | has 'predefined_labels' => ( | ||||||
13 | isa => 'ArrayRef', | ||||||
14 | is => 'rw', | ||||||
15 | ); | ||||||
16 | |||||||
17 | 10 | 10 | 2005 | no Any::Moose; | |||
10 | 23 | ||||||
10 | 108 | ||||||
18 | |||||||
19 | sub load_predefined { | ||||||
20 | 1 | 1 | 1 | 6 | my $self = shift; | ||
21 | 1 | 33 | 5 | my $class = ref $self || $self; | |||
22 | 1 | 2 | my $last_name; | ||||
23 | 1 | 50 | 10 | $last_name = lc $1 if $class =~ /::(\w+)$/; | |||
24 | |||||||
25 | 1 | 50 | 4 | return unless $self->signed_in; | |||
26 | 1 | 11 | my $base_url = $self->base_url; | ||||
27 | 1 | 6 | my $content = $self->fetch($self->base_url); | ||||
28 | 1 | 50 | 8 | if ( $content =~ /codesite_token\s*=\s*"(\w+)"/ ) { | |||
29 | 1 | 2 | my $token = $1; | ||||
30 | 1 | 6 | my $mech = $self->mech; | ||||
31 | # I tried to use $mech->post( $url, token => $token ) | ||||||
32 | # but without luck :( | ||||||
33 | 1 | 12 | $mech->update_html(<<"EOF"); | ||||
34 | |||||||
35 | method="POST" > | ||||||
36 | |||||||
37 | |||||||
38 | |||||||
39 | EOF | ||||||
40 | 1 | 8 | $mech->submit_form( form_number => 1 ); | ||||
41 | 1 | 50 | 8 | die "failed to post to OptionsJSON page" unless $mech->success; | |||
42 | |||||||
43 | 1 | 10 | my $js = $mech->content; | ||||
44 | 1 | 11 | my $object = from_json $js; | ||||
45 | 1 | 50 | 102 | return unless $object; | |||
46 | |||||||
47 | 1 | 18 | $self->predefined_status( { open => [], closed => [] } ); | ||||
48 | 1 | 3 | for my $type (qw/open closed/) { | ||||
49 | 2 | 4 | for ( @{ $object->{$type} } ) { | ||||
2 | 5 | ||||||
50 | 9 | 9 | push @{ $self->predefined_status->{$type} }, $_->{name}; | ||||
9 | 27 | ||||||
51 | } | ||||||
52 | } | ||||||
53 | |||||||
54 | 1 | 13 | $self->predefined_labels( [] ); | ||||
55 | 1 | 2 | for ( @{ $object->{labels} } ) { | ||||
1 | 4 | ||||||
56 | 23 | 21 | push @{ $self->predefined_labels }, $_->{name}; | ||||
23 | 51 | ||||||
57 | } | ||||||
58 | |||||||
59 | 1 | 21 | return 1; | ||||
60 | } | ||||||
61 | else { | ||||||
62 | 0 | warn "can't get user token"; | |||||
63 | 0 | return; | |||||
64 | } | ||||||
65 | |||||||
66 | } | ||||||
67 | |||||||
68 | 1; | ||||||
69 | |||||||
70 | __END__ |