File Coverage

blib/lib/VMware/vCloudDirector/Link.pm
Criterion Covered Total %
statement 25 41 60.9
branch 0 12 0.0
condition n/a
subroutine 11 15 73.3
pod n/a
total 36 68 52.9


line stmt bran cond sub pod time code
1             package VMware::vCloudDirector::Link;
2              
3             # ABSTRACT: Link within the vCloud
4              
5 1     1   2484 use strict;
  1         2  
  1         32  
6 1     1   6 use warnings;
  1         2  
  1         47  
7              
8             our $VERSION = '0.005'; # VERSION
9             our $AUTHORITY = 'cpan:NIGELM'; # AUTHORITY
10              
11 1     1   5 use Moose;
  1         2  
  1         6  
12 1     1   5950 use Method::Signatures;
  1         3  
  1         8  
13 1     1   318 use MooseX::Types::URI qw(Uri);
  1         3  
  1         14  
14 1     1   1702 use Ref::Util qw(is_plain_hashref);
  1         3  
  1         46  
15 1     1   6 use VMware::vCloudDirector::Error;
  1         2  
  1         290  
16              
17             # ------------------------------------------------------------------------
18              
19             has object => (
20             is => 'ro',
21             isa => 'VMware::vCloudDirector::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              
33             # ------------------------------------------------------------------------
34             around BUILDARGS => sub {
35             my ( $orig, $class, $first, @rest ) = @_;
36              
37             my $params = is_plain_hashref($first) ? $first : { $first, @rest };
38              
39             if ( $params->{hash} ) {
40             my $hash = delete $params->{hash};
41             $params->{href} = $hash->{-href} if ( exists( $hash->{-href} ) );
42             $params->{rel} = $hash->{-rel} if ( exists( $hash->{-rel} ) );
43             $params->{name} = $hash->{-name} if ( exists( $hash->{-name} ) );
44             if ( exists( $hash->{-type} ) ) {
45             my $type = $hash->{-type};
46             $params->{mime_type} = $type;
47             $params->{type} = $1 if ( $type =~ m|^application/vnd\..*\.(\w+)\+xml$| );
48             }
49             }
50              
51             return $class->$orig($params);
52             };
53              
54             # ------------------------------------------------------------------------
55              
56              
57 1 0   1   1013 method DELETE () { return $self->object->api->GET( $self->href ); }
  0     0      
  0            
  0            
58              
59              
60 1 0   1   678 method GET () { return $self->object->api->GET( $self->href ); }
  0     0      
  0            
  0            
61              
62              
63 1 0   1   90716 method POST ($xml_hash) { return $self->object->api->GET( $self->href, $xml_hash ); }
  0 0   0      
  0            
  0            
  0            
  0            
64              
65              
66 1 0   1   2164 method PUT ($xml_hash) { return $self->object->api->GET( $self->href, $xml_hash ); }
  0 0   0      
  0            
  0            
  0            
  0            
67              
68             # ------------------------------------------------------------------------
69              
70             __PACKAGE__->meta->make_immutable;
71              
72             1;
73              
74             __END__
75              
76             =pod
77              
78             =encoding UTF-8
79              
80             =head1 NAME
81              
82             VMware::vCloudDirector::Link - Link within the vCloud
83              
84             =head1 VERSION
85              
86             version 0.005
87              
88             =head3 DELETE
89              
90             Make a delete request to the URL in this link. Returns Objects. Failure will
91             generate an exception. See L<VMware::vCloudDirector::API/DELETE>.
92              
93             =head3 GET
94              
95             Make a get request to the URL in this link. Returns Objects. Failure will
96             generate an exception. See L<VMware::vCloudDirector::API/GET>.
97              
98             =head3 POST
99              
100             Make a post request with the specified payload to the URL in this link. Returns
101             Objects. Failure will generate an exception. See
102             L<VMware::vCloudDirector::API/POST>.
103              
104             =head3 PUT
105              
106             Make a put request with the specified payload to the URL in this link. Returns
107             Objects. Failure will generate an exception. See
108             L<VMware::vCloudDirector::API/PUT>.
109              
110             =head1 AUTHOR
111              
112             Nigel Metheringham <nigelm@cpan.org>
113              
114             =head1 COPYRIGHT AND LICENSE
115              
116             This software is copyright (c) 2017 by Nigel Metheringham.
117              
118             This is free software; you can redistribute it and/or modify it under
119             the same terms as the Perl 5 programming language system itself.
120              
121             =cut