vCloudDirector/ObjectContent.pm

filter: Statementstmt 98.6% 74 / 75 Branchbran 56.6% 17 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod n/a totaltotal 88.1% 104 / 118 SCAR 28.7
CC
17
Cov
87%
__ANON__
10.8
_listify
5.4
_build_links
4.1
CRAP 17.7
« vCloudDirector/Link.pm ↑ Summary vCloudDirector.pm »
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
BranchTrueFalseTotal
if scalar @_ > 0 0 1 1
45 1 my @links;
46 1 ▶ if ( exists( $self->hash->{Link} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->hash->{"Link"}) 1 0 1
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
BranchTrueFalseTotal
is_plain_hashref($first) ? : 0 19 19
58 19 ▶ if ( $params->{hash} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"hash"}) 19 0 19
59 19 my $top_hash = $params->{hash};
60  
61 19 my $hash;
62 19 ▶ if ( scalar( keys %{$top_hash} ) == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %{$top_hash;} == 1) { } 19 0 19
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
BranchTrueFalseTotal
if exists $hash->{"-href"} 19 0 19
73 19 ▶ $params->{rel} = $hash->{-rel} if ( exists( $hash->{-rel} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $hash->{"-rel"} 0 19 19
74 19 ▶ $params->{name} = $hash->{-name} if ( exists( $hash->{-name} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $hash->{"-name"} 18 1 19
75 19 ▶ $params->{id} = $hash->{-id} if ( exists( $hash->{-id} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $hash->{"-id"} 6 13 19
76 19 ▶ if ( exists( $hash->{-type} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hash->{"-type"}) 19 0 19
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
BranchTrueFalseTotal
if $type =~ m[^application/vnd\..*\.(\w+)\+xml$] 19 0 19
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
BranchTrueFalseTotal
unless scalar @_ > 0 0 1 1
if scalar @_ > 1 0 1 1
!defined($thing) ? : 0 1 1
ref $thing eq 'ARRAY' ? : 1 0 1
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
« vCloudDirector/Link.pm ↑ Summary vCloudDirector.pm »