| 1 | package Elive::DAO::Array; | ||||||||||||||||||||||||||||
| 2 | 27 | ▶ | use warnings; use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 27 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 27 | ▶ | use Mouse::Util::TypeConstraints; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 27 | ▶ | use parent qw{Elive::DAO::_Base}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 27 | ▶ | use Scalar::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 27 | ▶ | use Elive::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 27 | __PACKAGE__->mk_classdata('element_class'); | |||||||||||||||||||||||||||
| 13 | 27 | __PACKAGE__->mk_classdata('separator' => ','); | |||||||||||||||||||||||||||
| 14 | 27 | __PACKAGE__->has_metadata( '_is_copy' ); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | Elive::DAO::Array - Base class for arrays | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | Base class for arrays within entities. E.g. members property of | ||||||||||||||||||||||||||||
| 23 | Elive::Entity::participantList. | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head1 METHODS | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =cut | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | sub _build_array { | ||||||||||||||||||||||||||||
| 32 | 9 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_array: called CC=4 SCAR=14.8
| |||||||||||||||||||||||||||||
| 33 | 9 | my $spec = shift; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 9 | my $type = Elive::Util::_reftype( $spec ); | |||||||||||||||||||||||||||
| 36 | 9 | ▶ | $spec = [$spec] if ($type && $type ne 'ARRAY'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$type and $type ne "ARRAY"
MC/DC0%0/2
$type and $type ne "ARRAY"
$type
$type ne "ARRAY"
Truth table33%1/3
A and B
A= $typeB= $type ne "ARRAY"
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 9 | my @args; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 9 | ▶ | if ($type) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 9 | @args = map {Elive::Util::string($_)} @$spec; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | else { | ||||||||||||||||||||||||||||
| 44 | 0 | @args = split($class->separator, Elive::Util::string($spec)); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 9 | return \@args; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 27 | our $class = __PACKAGE__; | |||||||||||||||||||||||||||
| 51 | coerce $class => from 'ArrayRef|Str' | ||||||||||||||||||||||||||||
| 52 | => via { | ||||||||||||||||||||||||||||
| 53 | 0 | ▶ | $class->new( $_ ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 54 | 27 | }; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =head2 stringify | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | Serialises array members by joining individual elements. | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =cut | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | sub stringify { | ||||||||||||||||||||||||||||
| 63 | 208 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 208 | my $spec = shift; | |||||||||||||||||||||||||||
| 65 | 208 | ▶ | my $type = shift || $class->element_class; | ||||||||||||||||||||||||||
|
Condition66%2/3
shift() || $class->element_class
MC/DC50%1/2
shift() || $class->element_class
shift()
$class->element_class
Truth table66%2/3
A || B
A= shift()B= $class->element_class
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 208 | ▶ | $spec = $class | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $spec and ref $class
MC/DC50%1/2
not defined $spec and ref $class
not defined $spec
ref $class
Truth table66%2/3
not(A) and B
A= not defined $specB= ref $class
| |||||||||||||||||||||||||||||
| 68 | if !defined $spec && ref $class; | ||||||||||||||||||||||||||||
| 69 | 208 | my $arr = $class->_build_array( $spec ); | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 208 | return join($class->separator, sort map {Elive::Util::string($_, $type)} @$arr) | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =head2 new | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | my $array_obj = Elive::DAO::Array->new($array_ref); | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =cut | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | sub new { | ||||||||||||||||||||||||||||
| 81 | 57 | ▶ | my ($class, $spec) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 57 | my $array = $class->_build_array( $spec ); | |||||||||||||||||||||||||||
| 83 | 57 | return bless($array, $class); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =head2 add | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | $group->members->add('111111', '222222'); | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | Add elements to an array. | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =cut | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | sub add { | ||||||||||||||||||||||||||||
| 95 | 5 | ▶ | my ($self, @elems) = @_; | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=5 SCAR=16.7
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 5 | ▶ | if (my $element_class = $self->element_class) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 5 | foreach (@elems) { | |||||||||||||||||||||||||||
| 99 | 7 | ▶ | $_ = $element_class->new($_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $_ and not builtin::blessed($_)
MC/DC0%0/2
ref $_ and not builtin::blessed($_)
ref $_
not builtin::blessed($_)
Truth table66%2/3
A and not(B)
A= ref $_B= not builtin::blessed($_)
| |||||||||||||||||||||||||||||
| 100 | if ref && ! Scalar::Util::blessed($_); | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 5 | push (@$self, @elems); | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 5 | return $self; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 27 | 1; | |||||||||||||||||||||||||||