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             package REST::Cot::Fragment;
2             $REST::Cot::Fragment::VERSION = '0.005';
3 2     2   721 use 5.16.0;
  2         8  
4 2     2   11 use strict;
  2         5  
  2         51  
5 2     2   11 use warnings;
  2         10  
  2         61  
6              
7             # TODO: trace interface topology for SPORE spec?
8             # TODO: trace interface topology for Swagger spec?
9              
10 2     2   1035 use REST::Cot::Generators;
  2         5  
  2         145  
11             use overload
12 405     405   1119 '""' => sub { shift->{path}->() },
13 1     1   4 '~' => sub { shift->{progenitor}->() },
14 2     2   12 'fallback' => 1;
  2         3  
  2         25  
15              
16             our $AUTOLOAD;
17              
18             sub AUTOLOAD {
19 17     17   11067 my $self = shift;
20 17 50       48 my $type = ref($self)
21             or return;
22 17         33 my @args = @_;
23 17         21 my $fragment = $AUTOLOAD;
24              
25 17         70 $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   39 my $new = bless({}, __PACKAGE__);
33              
34 17         34 $new->{parent} = $self;
35 17         30 $new->{name} = $fragment;
36 17         32 $new->{args} = [@args];
37 17         32 $new->{client} = $self->{client};
38              
39 17         50 $new->{progenitor} = REST::Cot::Generators::progenitor($new);
40 17         47 $new->{path} = REST::Cot::Generators::path($new);
41 17         41 $new->{method} = REST::Cot::Generators::method($new);
42              
43 17         104 return $new;
44 17         56 };
45              
46 17         88 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__