| 1 | # | ||||||||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||||||||
| 3 | # | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | package Rex::Inventory::Hal::Object; | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | ▶ | use v5.14.4; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 1 | our $VERSION = '1.16.1'; # VERSION | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 13 | 0 | my $that = shift; | |||||||||||||||||||
| 14 | 0 | ▶ | my $proto = ref($that) || $that; | ||||||||||||||||||
|
Condition0%0/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table0%0/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||
| 15 | 0 | my $self = {@_}; | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 0 | bless( $self, $proto ); | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 0 | return $self; | |||||||||||||||||||
| 20 | } | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 3 | ▶ | sub has { | ||||||||||||||||||
|
Subroutine
has: called CC=3 SCAR=14.4
Pod
undocumented
| |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 3 | my ( $class, $keys ) = @_; | |||||||||||||||||||
| 25 | 0 | for my $k ( @{$keys} ) { | |||||||||||||||||||
| 26 | 13 | my $key = $k->{key}; | |||||||||||||||||||
| 27 | 13 | my $accessor = $k->{accessor}; | |||||||||||||||||||
| 28 | 13 | my $overwrite = $k->{overwrite}; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | 13 | ▶ | if ( !$overwrite ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | 12 | ▶ | *{"${class}::get_$accessor"} = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=32.5
| |||||||||||||||||||||
| 33 | 0 | my ($self) = @_; | |||||||||||||||||||
| 34 | 0 | ▶ | if ( $k->{"parent"} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | 0 | return $self->parent()->get($key); | |||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | else { | ||||||||||||||||||||
| 38 | 0 | ▶ | if ( ref($key) eq "ARRAY" ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | 0 | for my $_k ( @{$key} ) { | |||||||||||||||||||
| 40 | 0 | ▶ | if ( my $ret = $self->get($_k) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | 0 | return $ret; | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 0 | return ""; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | else { | ||||||||||||||||||||
| 48 | 0 | return $self->get($key); | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | 12 | }; | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | 13 | push( @{"${class}::items"}, $k ); | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | # returns the parent of the current object | ||||||||||||||||||||
| 62 | 0 | ▶ | sub parent { | ||||||||||||||||||
|
Subroutine
parent: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 0 | my ($self) = @_; | |||||||||||||||||||
| 65 | 0 | return $self->{"hal"}->get_object_by_udi( $self->{'info.parent'} ); | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 0 | ▶ | sub get { | ||||||||||||||||||
|
Subroutine
get: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 0 | my ( $self, $key ) = @_; | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 0 | ▶ | if ( ref( $self->{$key} ) eq "ARRAY" ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | 0 | return @{ $self->{$key} }; | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | return exists $self->{$key} | ||||||||||||||||||||
| 78 | 0 | ▶ | ? $self->{$key} | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | : ""; | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 0 | ▶ | sub get_all { | ||||||||||||||||||
|
Subroutine
get_all: not called CC=2 SCAR=10.5
Pod
undocumented
| |||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 0 | my ($self) = @_; | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 0 | my $r = ref($self); | |||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 90 | 0 | my @items = @{"${r}::items"}; | |||||||||||||||||||
| 91 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 0 | my $ret; | |||||||||||||||||||
| 94 | 0 | for my $itm (@items) { | |||||||||||||||||||
| 95 | 0 | my $f = "get_" . $itm->{"accessor"}; | |||||||||||||||||||
| 96 | 0 | $ret->{ $itm->{"accessor"} } = $self->$f(); | |||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 0 | return $ret; | |||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 1 | 1; | |||||||||||||||||||