File Coverage

blib/lib/Net/Fastly/Model.pm
Criterion Covered Total %
statement 11 38 28.9
branch 1 4 25.0
condition n/a
subroutine 4 14 28.5
pod 3 3 100.0
total 19 59 32.2


line stmt bran cond sub pod time code
1             package Net::Fastly::Model;
2              
3 4     4   34 use strict;
  4         11  
  4         132  
4 4     4   20 use base qw(Class::Accessor::Fast);
  4         17  
  4         1889  
5              
6             =head1 NAME
7              
8             Net::Fastly::Model - base class for all classes
9              
10             =head1 METHODS
11              
12             =head2 new
13              
14             Create a new object, passing in a Fastly object that can get other objects
15              
16             =cut
17             sub new {
18 0     0 1 0 my $class = shift;
19 0         0 my $fetcher = shift;
20 0         0 my %opts = @_;
21 0         0 $opts{_fetcher} = $fetcher;
22 0         0 return bless \%opts, $class;
23             }
24              
25 0     0   0 sub _fetcher { shift->{_fetcher} }
26              
27             sub _as_hash {
28 0     0   0 my $self = shift;
29 0         0 my %ret;
30 0         0 foreach my $key (keys %$self) {
31 0 0       0 $ret{$key} = $self->{$key} unless $key =~ m!^_!;
32             }
33 0         0 return %ret;
34             }
35              
36             sub _path {
37 52     52   107 my $class = shift;
38 52 50       143 $class = ref($class) if ref($class);
39 52         387 my ($path) = (lc($class) =~ m!::([^:]+)$!);
40 52         147 return $path;
41             }
42              
43             sub _get_path {
44 0     0   0 my $class = shift;
45 0         0 my $id = shift;
46 0         0 return "/".$class->_path."/$id";
47             }
48              
49             sub _post_path {
50 0     0   0 my $class = shift;
51 0         0 return "/".$class->_path;
52             }
53 52     52   215 sub _skip_list { 0 }
54 0     0     sub _list_path { shift->_post_path(@_) }
55              
56              
57             sub _put_path {
58 0     0     my $class = shift;
59 0           my $obj = shift;
60 0           return $class->_get_path($obj->id);
61             }
62            
63             sub _delete_path {
64 0     0     my $class = shift;
65 0           my $obj = shift;
66 0           return $class->_put_path($obj);
67             }
68              
69             =head2 save
70              
71             Save this object. Equivalent to
72              
73             $fastly->update_($object);
74              
75             =cut
76             sub save {
77 0     0 1   my $self = shift;
78 0           $self->_fetcher->_update(ref($self), $self);
79             }
80              
81             =head2 delete
82              
83             Delete this object. Equivalent to
84              
85             $fastly->delete_($object);
86              
87             =cut
88             sub delete {
89 0     0 1   my $self = shift;
90 0           $self->_fetcher->_delete(ref($self), $self);
91             }
92              
93              
94             1;