File Coverage

blib/lib/VMware/vCloudDirector2/Link.pm
Criterion Covered Total %
statement 26 45 57.7
branch 0 14 0.0
condition n/a
subroutine 12 17 70.5
pod n/a
total 38 76 50.0


line stmt bran cond sub pod time code
1             package VMware::vCloudDirector2::Link;
2              
3             # ABSTRACT: Link within the vCloud
4              
5 4     4   29 use strict;
  4         10  
  4         128  
6 4     4   22 use warnings;
  4         11  
  4         199  
7              
8             our $VERSION = '0.108'; # VERSION
9             our $AUTHORITY = 'cpan:NIGELM'; # AUTHORITY
10              
11 4     4   25 use Moose;
  4         9  
  4         34  
12 4     4   28954 use Method::Signatures;
  4         12  
  4         39  
13 4     4   1977 use MooseX::Types::URI qw(Uri);
  4         10  
  4         43  
14 4     4   8283 use Ref::Util qw(is_plain_hashref);
  4         11  
  4         229  
15 4     4   28 use VMware::vCloudDirector2::Error;
  4         10  
  4         2457  
16              
17             # ------------------------------------------------------------------------
18              
19             has object => (
20             is => 'ro',
21             isa => 'VMware::vCloudDirector2::Object',
22             required => 1,
23             weak_ref => 1,
24             documentation => 'Parent object of link'
25             );
26              
27             has mime_type => ( is => 'ro', isa => 'Str', predicate => 'has_mime_type' );
28             has href => ( is => 'ro', isa => Uri, required => 1, coerce => 1 );
29             has rel => ( is => 'ro', isa => 'Str', required => 1 );
30             has name => ( is => 'ro', isa => 'Str', predicate => 'has_name' );
31             has type => ( is => 'ro', isa => 'Str' );
32             has is_json => ( is => 'ro', isa => 'Bool' );
33              
34             # ------------------------------------------------------------------------
35             around BUILDARGS => sub {
36             my ( $orig, $class, $first, @rest ) = @_;
37              
38             my $params = is_plain_hashref($first) ? $first : { $first, @rest };
39              
40             if ( $params->{hash} ) {
41             my $hash = delete $params->{hash};
42             $params->{href} = $hash->{href} if ( exists( $hash->{href} ) and defined( $hash->{href} ) );
43             $params->{rel} = $hash->{rel} if ( exists( $hash->{rel} ) and defined( $hash->{rel} ) );
44             $params->{name} = $hash->{name} if ( exists( $hash->{name} ) and defined( $hash->{name} ) );
45             if ( exists( $hash->{type} ) and defined( $hash->{type} ) ) {
46             my $type = $hash->{type};
47             $params->{mime_type} = $type;
48             if ( $type =~ m!^application/vnd\..*\.(\w+)\+(json|xml)$! ) {
49             $params->{type} = $1;
50             $params->{is_json} = ( $2 eq 'json' ) ? 1 : 0;
51             }
52             }
53             }
54              
55             return $class->$orig($params);
56             };
57              
58             # ------------------------------------------------------------------------
59              
60              
61 4 0   4   5553 method DELETE () { return $self->object->api->DELETE( $self->href ); }
  0     0      
  0            
  0            
62              
63              
64 4 0   4   3402 method GET () { return $self->object->api->GET( $self->href ); }
  0     0      
  0            
  0            
65 4 0   4   3187 method GET_hash () { return $self->object->api->GET_hash( $self->href ); }
  0     0      
  0            
  0            
66              
67              
68 4 0   4   462794 method POST ($hash) { return $self->object->api->POST( $self->href, $hash, $self->mime_type ); }
  0 0   0      
  0            
  0            
  0            
  0            
69              
70              
71 4 0   4   11298 method PUT ($hash) { return $self->object->api->PUT( $self->href, $hash, $self->mime_type ); }
  0 0   0      
  0            
  0            
  0            
  0            
72              
73             # ------------------------------------------------------------------------
74              
75             __PACKAGE__->meta->make_immutable;
76              
77             1;
78              
79             __END__
80              
81             =pod
82              
83             =encoding UTF-8
84              
85             =head1 NAME
86              
87             VMware::vCloudDirector2::Link - Link within the vCloud
88              
89             =head1 VERSION
90              
91             version 0.108
92              
93             =head3 DELETE
94              
95             Make a delete request to the URL in this link. Returns Objects. Failure will
96             generate an exception. See L<VMware::vCloudDirector2::API/DELETE>.
97              
98             =head3 GET
99              
100             Make a get request to the URL in this link. Returns Objects. Failure will
101             generate an exception. See L<VMware::vCloudDirector2::API/GET>.
102              
103             =head3 GET_hash
104              
105             Make a get request to the URL in this link. Returns a decoded hash. Failure
106             will generate an exception. See L<VMware::vCloudDirector2::API/GET_hash>.
107              
108             =head3 POST
109              
110             Make a post request with the specified payload to the URL in this link. Returns
111             Objects. Failure will generate an exception. See
112             L<VMware::vCloudDirector2::API/POST>.
113              
114             =head3 PUT
115              
116             Make a put request with the specified payload to the URL in this link. Returns
117             Objects. Failure will generate an exception. See
118             L<VMware::vCloudDirector2::API/PUT>.
119              
120             =head1 AUTHOR
121              
122             Nigel Metheringham <nigelm@cpan.org>
123              
124             =head1 COPYRIGHT AND LICENSE
125              
126             This software is copyright (c) 2019 by Nigel Metheringham.
127              
128             This is free software; you can redistribute it and/or modify it under
129             the same terms as the Perl 5 programming language system itself.
130              
131             =cut