Lighthouse/Token.pm

filter: Statementstmt 97.1% 34 / 35 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 95.5% 43 / 45 CC 3 SCAR 4.1
CC
3
Cov
95%
load
2.0
load_from_xml
2.0
BEGIN
1.0
CRAP 1.5
« Lighthouse/Base.pm ↑ Summary Lighthouse/User/Membership.pm »
1 package Net::Lighthouse::Token;
2 11 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use Params::Validate ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use Net::Lighthouse::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 extends 'Net::Lighthouse::Base';
6  
7 # read only attr
8 11 has 'created_at' => (
9 isa => 'DateTime',
10 is => 'ro',
11 );
12  
13 11 has 'user_id' => (
14 isa => 'Int',
15 is => 'ro',
16 );
17  
18 11 has 'project_id' => (
19 isa => 'Maybe[Int]',
20 is => 'ro',
21 );
22  
23 11 has 'read_only' => (
24 isa => 'Bool',
25 is => 'ro',
26 );
27  
28 11 has 'token' => (
29 isa => 'Str',
30 is => 'ro',
31 );
32  
33 11 has [ 'account', 'note' ] => (
34 isa => 'Maybe[Str]',
35 is => 'ro',
36 );
37  
38 11 ▶no Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 11 __PACKAGE__->meta->make_immutable;
40  
41 1 ▶sub load {
Subroutine load: called CC=2 SCAR=7.1
Pod documented
42 1 my $self = shift;
43 1 validate_pos( @_, { type => SCALAR, regex => qr/^\w{40}$/ } );
44 1 my $token = shift;
45  
46 1 my $ua = $self->ua;
47 1 my $url = $self->base_url . '/tokens/' . $token . '.xml';
48 1 my $res = $ua->get( $url );
49 1 ▶ if ( $res->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 1 0 1
50 1 $self->load_from_xml( $res->content );
51 }
52 else {
53 0 die "try to get $url failed: "
54 . $res->status_line . "\n"
55 . $res->content;
56 }
57 }
58  
59 1 ▶sub load_from_xml {
Subroutine load_from_xml: called CC=2 SCAR=6.9
Pod documented
60 1 my $self = shift;
61 1 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 for my $k ( keys %$ref ) {
66 7 $self->{$k} = $ref->{$k};
67 }
68 1 return $self;
69 }
70  
71 11 1;
72  
73 __END__
« Lighthouse/Base.pm ↑ Summary Lighthouse/User/Membership.pm »