| 1 | package VMware::vCloudDirector::ObjectContent; | ||||||||||||||||||||||
| 2 | |||||||||||||||||||||||
| 3 | # ABSTRACT: A vCloud Object content | ||||||||||||||||||||||
| 4 | |||||||||||||||||||||||
| 5 | 4 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | 4 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | 4 | our $VERSION = '0.007'; # VERSION | |||||||||||||||||||||
| 9 | 4 | our $AUTHORITY = 'cpan:NIGELM'; # AUTHORITY | |||||||||||||||||||||
| 10 | |||||||||||||||||||||||
| 11 | 4 | ▶ | use Moose; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 12 | 4 | ▶ | use Method::Signatures; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 13 | 4 | ▶ | use MooseX::Types::URI qw(Uri); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 14 | 4 | ▶ | use Const::Fast; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 15 | 4 | ▶ | use Ref::Util qw(is_plain_hashref); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 16 | 4 | ▶ | use VMware::vCloudDirector::Link; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 17 | |||||||||||||||||||||||
| 18 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||
| 19 | |||||||||||||||||||||||
| 20 | 4 | has object => ( | |||||||||||||||||||||
| 21 | is => 'ro', | ||||||||||||||||||||||
| 22 | isa => 'VMware::vCloudDirector::Object', | ||||||||||||||||||||||
| 23 | required => 1, | ||||||||||||||||||||||
| 24 | weak_ref => 1, | ||||||||||||||||||||||
| 25 | documentation => 'Parent object' | ||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||
| 27 | |||||||||||||||||||||||
| 28 | 4 | has mime_type => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||||||||||||||
| 29 | 4 | has href => ( is => 'ro', isa => Uri, required => 1, coerce => 1 ); | |||||||||||||||||||||
| 30 | 4 | has type => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||||||||||||||
| 31 | 4 | has hash => ( is => 'ro', isa => 'HashRef', required => 1, writer => '_set_hash' ); | |||||||||||||||||||||
| 32 | 4 | has name => ( is => 'ro', isa => 'Str', predicate => 'has_name' ); | |||||||||||||||||||||
| 33 | 4 | has id => ( is => 'ro', isa => 'Str', predicate => 'has_id' ); | |||||||||||||||||||||
| 34 | |||||||||||||||||||||||
| 35 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||
| 36 | |||||||||||||||||||||||
| 37 | 4 | has links => ( | |||||||||||||||||||||
| 38 | is => 'ro', | ||||||||||||||||||||||
| 39 | isa => 'ArrayRef[VMware::vCloudDirector::Link]', | ||||||||||||||||||||||
| 40 | lazy => 1, | ||||||||||||||||||||||
| 41 | builder => '_build_links' | ||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||
| 43 | |||||||||||||||||||||||
| 44 | 4 | ▶ | method _build_links () { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
_build_links: called CC=4 SCAR=14.0
Branch: 1 branch
| |||||||||||||||||||||||
| 45 | 1 | my @links; | |||||||||||||||||||||
| 46 | 1 | ▶ | if ( exists( $self->hash->{Link} ) ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 47 | push( @links, VMware::vCloudDirector::Link->new( hash => $_, object => $self->object ) ) | ||||||||||||||||||||||
| 48 | 1 | foreach ( $self->_listify( $self->hash->{Link} ) ); | |||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||
| 50 | 1 | return \@links; | |||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||
| 52 | |||||||||||||||||||||||
| 53 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||
| 54 | around BUILDARGS => sub { | ||||||||||||||||||||||
| 55 | 19 | ▶ | my ( $orig, $class, $first, @rest ) = @_; | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=23.8
| |||||||||||||||||||||||
| 56 | |||||||||||||||||||||||
| 57 | 19 | ▶ | my $params = is_plain_hashref($first) ? $first : { $first, @rest }; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 58 | 19 | ▶ | if ( $params->{hash} ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 59 | 19 | my $top_hash = $params->{hash}; | |||||||||||||||||||||
| 60 | |||||||||||||||||||||||
| 61 | 19 | my $hash; | |||||||||||||||||||||
| 62 | 19 | ▶ | if ( scalar( keys %{$top_hash} ) == 1 ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 63 | 19 | my $type = ( keys %{$top_hash} )[0]; | |||||||||||||||||||||
| 64 | 19 | $hash = $top_hash->{$type}; | |||||||||||||||||||||
| 65 | 19 | $params->{type} = $type; | |||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||
| 67 | else { | ||||||||||||||||||||||
| 68 | 0 | $hash = $top_hash; | |||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||
| 70 | 19 | const $params->{hash} => $hash; # force hash read-only to stop people playing | |||||||||||||||||||||
| 71 | |||||||||||||||||||||||
| 72 | 19 | ▶ | $params->{href} = $hash->{-href} if ( exists( $hash->{-href} ) ); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 73 | 19 | ▶ | $params->{rel} = $hash->{-rel} if ( exists( $hash->{-rel} ) ); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 74 | 19 | ▶ | $params->{name} = $hash->{-name} if ( exists( $hash->{-name} ) ); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 75 | 19 | ▶ | $params->{id} = $hash->{-id} if ( exists( $hash->{-id} ) ); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 76 | 19 | ▶ | if ( exists( $hash->{-type} ) ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 77 | 19 | my $type = $hash->{-type}; | |||||||||||||||||||||
| 78 | 19 | $params->{mime_type} = $type; | |||||||||||||||||||||
| 79 | 19 | ▶ | $params->{type} = $1 if ( $type =~ m|^application/vnd\..*\.(\w+)\+xml$| ); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||
| 82 | 19 | return $class->$orig($params); | |||||||||||||||||||||
| 83 | 4 | }; | |||||||||||||||||||||
| 84 | |||||||||||||||||||||||
| 85 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||
| 86 | 4 | ▶ | method _listify ($thing) { !defined $thing ? () : ( ( ref $thing eq 'ARRAY' ) ? @{$thing} : $thing ) } | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
_listify: called CC=5 SCAR=16.8
Branch: 4 branches
| |||||||||||||||||||||||
| 87 | |||||||||||||||||||||||
| 88 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||
| 89 | |||||||||||||||||||||||
| 90 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||
| 91 | |||||||||||||||||||||||
| 92 | 4 | 1; | |||||||||||||||||||||
| 93 | |||||||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||||
| 95 | |||||||||||||||||||||||
| 96 | =pod | ||||||||||||||||||||||
| 97 | |||||||||||||||||||||||
| 98 | =encoding UTF-8 | ||||||||||||||||||||||
| 99 | |||||||||||||||||||||||
| 100 | =head1 NAME | ||||||||||||||||||||||
| 101 | |||||||||||||||||||||||
| 102 | VMware::vCloudDirector::ObjectContent - A vCloud Object content | ||||||||||||||||||||||
| 103 | |||||||||||||||||||||||
| 104 | =head1 VERSION | ||||||||||||||||||||||
| 105 | |||||||||||||||||||||||
| 106 | version 0.007 | ||||||||||||||||||||||
| 107 | |||||||||||||||||||||||
| 108 | =head1 AUTHOR | ||||||||||||||||||||||
| 109 | |||||||||||||||||||||||
| 110 | Nigel Metheringham <nigelm@cpan.org> | ||||||||||||||||||||||
| 111 | |||||||||||||||||||||||
| 112 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||
| 113 | |||||||||||||||||||||||
| 114 | This software is copyright (c) 2017 by Nigel Metheringham. | ||||||||||||||||||||||
| 115 | |||||||||||||||||||||||
| 116 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||
| 117 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||
| 118 | |||||||||||||||||||||||
| 119 | =cut | ||||||||||||||||||||||