| 1 | package Elive::Entity::Group::Members; | ||||||||||||||
| 2 | 27 | ▶ | use warnings; use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | |||||||||||||||
| 4 | =head1 NAME | ||||||||||||||
| 5 | |||||||||||||||
| 6 | Elive::Entity::Group::Members - Group Members entity class | ||||||||||||||
| 7 | |||||||||||||||
| 8 | =cut | ||||||||||||||
| 9 | |||||||||||||||
| 10 | 27 | ▶ | use Mouse; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 27 | ▶ | use Mouse::Util::TypeConstraints; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 27 | ▶ | use Scalar::Util; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 27 | ▶ | use Elive::Util; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | |||||||||||||||
| 15 | 27 | ▶ | use Elive::Entity::Group; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | 27 | ▶ | use Elive::Entity::User; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | |||||||||||||||
| 18 | 27 | extends 'Elive::DAO::Array'; | |||||||||||||
| 19 | 27 | __PACKAGE__->separator(','); | |||||||||||||
| 20 | |||||||||||||||
| 21 | # Elements are likley to be | ||||||||||||||
| 22 | # - group objects | ||||||||||||||
| 23 | # - user-ids as strings: 'someuser' | ||||||||||||||
| 24 | # - group-ids strings: '*my_group' | ||||||||||||||
| 25 | |||||||||||||||
| 26 | 27 | __PACKAGE__->element_class('Elive::Entity::Group|Str'); | |||||||||||||
| 27 | |||||||||||||||
| 28 | sub _build_array { | ||||||||||||||
| 29 | 100 | ▶ | my $class = shift; | ||||||||||||
|
Subroutine
_build_array: called CC=2 SCAR=6.9
| |||||||||||||||
| 30 | 100 | my $spec = shift; | |||||||||||||
| 31 | |||||||||||||||
| 32 | 100 | my $type = Elive::Util::_reftype( $spec ); | |||||||||||||
| 33 | |||||||||||||||
| 34 | 100 | my @members; | |||||||||||||
| 35 | |||||||||||||||
| 36 | 100 | ▶ | if ($type eq 'ARRAY') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 37 | 99 | @members = map {$class->__build_elem($_)} @$spec; | |||||||||||||
| 38 | } | ||||||||||||||
| 39 | else { | ||||||||||||||
| 40 | 1 | @members = split($class->separator, Elive::Util::string( $spec )); | |||||||||||||
| 41 | } | ||||||||||||||
| 42 | |||||||||||||||
| 43 | 100 | return \@members; | |||||||||||||
| 44 | } | ||||||||||||||
| 45 | |||||||||||||||
| 46 | sub __build_elem { | ||||||||||||||
| 47 | 284 | ▶ | my $class = shift; | ||||||||||||
|
Subroutine
__build_elem: called CC=5 SCAR=16.1
| |||||||||||||||
| 48 | 284 | my $elem = shift; | |||||||||||||
| 49 | |||||||||||||||
| 50 | 284 | my $reftype = Elive::Util::_reftype($elem); | |||||||||||||
| 51 | |||||||||||||||
| 52 | 284 | ▶ | if ($reftype eq 'HASH') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | # blessed or unblessed user struct | ||||||||||||||
| 54 | 35 | ▶ | if (exists $elem->{userId}) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 55 | 27 | return $elem->{userId}; | |||||||||||||
| 56 | } | ||||||||||||||
| 57 | elsif (exists $elem->{groupId}) { | ||||||||||||||
| 58 | |||||||||||||||
| 59 | 8 | ▶ | $elem = Elive::Entity::Group->new($elem) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 60 | unless Scalar::Util::blessed($elem); | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 8 | return $elem; | |||||||||||||
| 63 | } | ||||||||||||||
| 64 | } | ||||||||||||||
| 65 | |||||||||||||||
| 66 | 249 | return Elive::Util::string($elem); | |||||||||||||
| 67 | } | ||||||||||||||
| 68 | |||||||||||||||
| 69 | 27 | our $class = 'Elive::Entity::Group::Members'; | |||||||||||||
| 70 | coerce $class => from 'ArrayRef|Str' | ||||||||||||||
| 71 | => via { | ||||||||||||||
| 72 | 23 | ▶ | $class->new( $_ ); | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 73 | 27 | }; | |||||||||||||
| 74 | |||||||||||||||
| 75 | 27 | 1; | |||||||||||||