File Coverage

blib/lib/REST/Cot/Fragment.pm
Criterion Covered Total %
statement 32 39 82.0
branch 1 2 50.0
condition n/a
subroutine 9 17 52.9
pod 0 6 0.0
total 42 64 65.6


line stmt bran cond sub pod time code
1 2     2   666 use 5.16.0;
  2         6  
2 2     2   10 use strict;
  2         3  
  2         41  
3 2     2   9 use warnings;
  2         9  
  2         86  
4              
5             # TODO: add some response inflator
6             # TODO: trace interface topology for SPORE spec?
7             # TODO: trace interface topology for Swagger spec?
8              
9             package REST::Cot::Fragment;
10 2     2   984 use REST::Cot::Generators;
  2         4  
  2         144  
11             use overload
12 405     405   1089 '""' => sub { shift->{path}->() },
13 1     1   5 '~' => sub { shift->{progenitor}->() },
14 2     2   11 'fallback' => 1;
  2         4  
  2         23  
15              
16             our $AUTOLOAD;
17              
18             sub AUTOLOAD {
19 17     17   9730 my $self = shift;
20 17 50       53 my $type = ref($self)
21             or return;
22 17         28 my @args = @_;
23 17         24 my $fragment = $AUTOLOAD;
24              
25 17         66 $fragment =~ s/.*:://;
26              
27             # DISABLE fragment caching, this is slower but the interface works correctly
28             # return $self->{fragments}->{$fragment}->()
29             # if exists $self->{fragments}->{$fragment};
30              
31             my $sub = sub {
32 17     17   33 my $new = bless({}, __PACKAGE__);
33              
34 17         33 $new->{parent} = $self;
35 17         34 $new->{name} = $fragment;
36 17         34 $new->{args} = [@args];
37 17         46 $new->{client} = $self->{client};
38              
39 17         47 $new->{progenitor} = REST::Cot::Generators::progenitor($new);
40 17         46 $new->{path} = REST::Cot::Generators::path($new);
41 17         43 $new->{method} = REST::Cot::Generators::method($new);
42              
43 17         95 return $new;
44 17         60 };
45              
46 17         85 return ($self->{fragments}->{$fragment} = $sub)->();
47             }
48              
49       0     sub DESTROY {
50             # We don't want this being called via autoload since an object is out of scope by this point
51             }
52              
53 0     0 0   sub GET { shift->{method}->( 'GET', @_ ); }
54 0     0 0   sub PUT { shift->{method}->( 'PUT', @_ ); }
55 0     0 0   sub PATCH { shift->{method}->( 'PATCH', @_ ); }
56 0     0 0   sub POST { shift->{method}->( 'POST', @_ ); }
57 0     0     sub DELETE { shift->{method}->( 'DELETE', @_ ); }
58 0     0 0   sub OPTIONS { shift->{method}->( 'OPTIONS', @_ ); }
59 0     0 0   sub HEAD { shift->{method}->( 'HEAD', @_ ); }
60              
61             1;
62              
63             __END__