| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::Lighthouse::Token; | 
| 2 | 11 |  |  | 11 |  | 1657 | use Any::Moose; | 
|  | 11 |  |  |  |  | 32263 |  | 
|  | 11 |  |  |  |  | 470 |  | 
| 3 | 11 |  |  | 11 |  | 7924 | use Params::Validate ':all'; | 
|  | 11 |  |  |  |  | 21 |  | 
|  | 11 |  |  |  |  | 2194 |  | 
| 4 | 11 |  |  | 11 |  | 674 | use Net::Lighthouse::Util; | 
|  | 11 |  |  |  |  | 63 |  | 
|  | 11 |  |  |  |  | 1349 |  | 
| 5 |  |  |  |  |  |  | extends 'Net::Lighthouse::Base'; | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | # read only attr | 
| 8 |  |  |  |  |  |  | has 'created_at' => ( | 
| 9 |  |  |  |  |  |  | isa => 'DateTime', | 
| 10 |  |  |  |  |  |  | is  => 'ro', | 
| 11 |  |  |  |  |  |  | ); | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | has 'user_id' => ( | 
| 14 |  |  |  |  |  |  | isa => 'Int', | 
| 15 |  |  |  |  |  |  | is  => 'ro', | 
| 16 |  |  |  |  |  |  | ); | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | has 'project_id' => ( | 
| 19 |  |  |  |  |  |  | isa => 'Maybe[Int]', | 
| 20 |  |  |  |  |  |  | is  => 'ro', | 
| 21 |  |  |  |  |  |  | ); | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | has 'read_only' => ( | 
| 24 |  |  |  |  |  |  | isa => 'Bool', | 
| 25 |  |  |  |  |  |  | is  => 'ro', | 
| 26 |  |  |  |  |  |  | ); | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | has 'token' => ( | 
| 29 |  |  |  |  |  |  | isa => 'Str', | 
| 30 |  |  |  |  |  |  | is  => 'ro', | 
| 31 |  |  |  |  |  |  | ); | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | has [ 'account', 'note' ] => ( | 
| 34 |  |  |  |  |  |  | isa => 'Maybe[Str]', | 
| 35 |  |  |  |  |  |  | is  => 'ro', | 
| 36 |  |  |  |  |  |  | ); | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 11 |  |  | 11 |  | 63 | no Any::Moose; | 
|  | 11 |  |  |  |  | 26 |  | 
|  | 11 |  |  |  |  | 62 |  | 
| 39 |  |  |  |  |  |  | __PACKAGE__->meta->make_immutable; | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | sub load { | 
| 42 | 1 |  |  | 1 | 1 | 5495 | my $self = shift; | 
| 43 | 1 |  |  |  |  | 33 | validate_pos( @_, { type => SCALAR, regex => qr/^\w{40}$/ } ); | 
| 44 | 1 |  |  |  |  | 14 | my $token = shift; | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 1 |  |  |  |  | 9 | my $ua = $self->ua; | 
| 47 | 1 |  |  |  |  | 7 | my $url = $self->base_url . '/tokens/' . $token . '.xml'; | 
| 48 | 1 |  |  |  |  | 8 | my $res = $ua->get( $url ); | 
| 49 | 1 | 50 |  |  |  | 57 | if ( $res->is_success ) { | 
| 50 | 1 |  |  |  |  | 46 | $self->load_from_xml( $res->content ); | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  | else { | 
| 53 | 0 |  |  |  |  | 0 | die "try to get $url failed: " | 
| 54 |  |  |  |  |  |  | . $res->status_line . "\n" | 
| 55 |  |  |  |  |  |  | . $res->content; | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | sub load_from_xml { | 
| 60 | 1 |  |  | 1 | 1 | 129 | my $self = shift; | 
| 61 | 1 |  |  |  |  | 9 | my $ref = Net::Lighthouse::Util->translate_from_xml(shift); | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | # dirty hack: some attrs are read-only, and Mouse doesn't support | 
| 64 |  |  |  |  |  |  | # writer => '...' | 
| 65 | 1 |  |  |  |  | 5 | for my $k ( keys %$ref ) { | 
| 66 | 7 |  |  |  |  | 28 | $self->{$k} = $ref->{$k}; | 
| 67 |  |  |  |  |  |  | } | 
| 68 | 1 |  |  |  |  | 9 | return $self; | 
| 69 |  |  |  |  |  |  | } | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | 1; | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | __END__ |