File Coverage

blib/lib/Net/Fastly/User.pm
Criterion Covered Total %
statement 6 17 35.2
branch 0 4 0.0
condition 0 7 0.0
subroutine 2 5 40.0
pod 3 3 100.0
total 11 36 30.5


line stmt bran cond sub pod time code
1             package Net::Fastly::User;
2              
3 4     4   14 use strict;
  4         4  
  4         101  
4 4     4   12 use base qw(Net::Fastly::Model);
  4         3  
  4         793  
5              
6             Net::Fastly::User->mk_accessors(qw(id name login customer_id role));
7              
8             =head1 NAME
9              
10             Net::Fastly::User - a representation of a user
11              
12             =head1 ACCESSORS
13              
14             =head2 id
15              
16             The id of this user
17              
18             =head2 name
19              
20             The name of this user
21              
22             =head2 customer_id
23              
24             The id of the customer this user belongs to
25              
26             =head2 role
27              
28             The role this user has (one of admin, owner, superuser, user, engineer, billing)
29              
30             =cut
31              
32             =head1 METHODS
33              
34              
35             =head2 customer
36              
37             Get the Customer object this user belongs to.
38              
39             =cut
40             sub customer {
41 0     0 1   my $self = shift;
42 0   0       return $self->{_customer} ||= $self->_fetcher->_get("Net::Fastly::Customer", $self->customer_id);
43             }
44              
45             =head2 owner
46              
47             Where this user is the owner of their Customer.
48              
49             =cut
50             sub owner {
51 0     0 1   my $self = shift;
52 0           $self->customer->owner_id eq $self->id;
53             }
54              
55             our %PRIORITIES = (
56             admin => 1,
57             owner => 10,
58             superuser => 10,
59             user => 20,
60             engineer => 30,
61             billing => 30,
62             );
63              
64             =head2 can_do
65              
66             Whether or not this user has the capabilities of a given role.
67              
68             So for example a super user I superuser or user or engineer or billing.
69              
70             =cut
71             sub can_do {
72 0     0 1   my $self = shift;
73 0           my $test_role = shift;
74 0   0       my $test_priority = $PRIORITIES{$test_role} || 1000;
75 0   0       my $my_priority = $PRIORITIES{$self->role} || 1000;
76            
77 0 0         if ($test_priority == $my_priority) {
78 0 0         $test_role eq 'owner' ? $self->owner : $test_role eq $self->role;
79             } else {
80 0           $my_priority < $test_priority;
81             }
82             }
83              
84              
85             1;