Elive/DAO/Singleton.pm

filter: Statementstmt 76.4% 13 / 17 Branchbran 25.0% 1 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.0% 4 / 5 Podpod 100% 2 / 2 totaltotal 60.6% 20 / 33 CC 4 SCAR 16.8
CC
4
Cov
58%
get
12.0
list
2.0
BEGIN
1.0
CRAP 5.4
« Elive/Entity/Group.pm ↑ Summary Elive/Entity/User.pm »
1 package Elive::DAO::Singleton;
2 21 ▶use warnings; use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 21 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 Elive::DAO::Singleton - Singleton mixin class
9  
10 =head1 DESCRIPTION
11  
12 This mixin class provides a C<get> method for fetching the singleton
13 object. It also overrides the L<Elive::DAO> list method, to return just
14 the singleton object in a one element array.
15  
16 Typical usage is:
17  
18 package Elive::Entity::SomeEntity;
19 use warnings; use strict;
20  
21 use Mouse;
22  
23 extends 'Elive::DAO::Singleton', 'Elive::Entity';
24  
25 =cut
26  
27 =head1 METHODS
28  
29 =head2 get
30  
31 my $server = Elive::Entity::ServerDetails->get(connection => $connection);
32  
33 Gets the singleton object.
34  
35 =cut
36  
37 sub get {
38 0 ▶ my ($class, %opt) = @_;
Subroutine get: not called CC=3 SCAR=24.8
Pod documented
39  
40 0 my $object_list = $class->list(%opt);
41  
42 0 ▶ die "unable to get $class\n"
Branch: 1 branch
BranchTrueFalseTotal
unless Elive::Util::_reftype($object_list) eq "ARRAY" and $object_list->[0] 0 0 0
Condition0%0/3
Elive::Util::_reftype($object_list) eq "ARRAY" and $object_list->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
Elive::Util::_reftype($object_list) eq "ARRAY" and $object_list->[0]
Elive::Util::_reftype($object_list) eq "ARRAY" $object_list->[0]
Truth table0%0/3
A and B
A= Elive::Util::_reftype($object_list) eq "ARRAY"B= $object_list->[0]
ABresult
0X0
100
111
43 unless (Elive::Util::_reftype($object_list) eq 'ARRAY'
44 && $object_list->[0]);
45  
46 0 return $object_list->[0];
47 }
48  
49 =head2 list
50  
51 my $server_list = Elive::Entity::SomeEntity->list();
52 my $server_obj = $server_list->[0];
53  
54 Returns the singleton object in a one element array .
55  
56 =cut
57  
58 sub list {
59 5 ▶ my ($class, %opt) = @_;
Subroutine list: called CC=2 SCAR=7.1
Pod documented
60  
61 croak "filter not applicable to singleton class: $class"
62 5 ▶ if ($opt{filter});
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"filter"} 0 5 5
63  
64 5 return $class->_fetch({}, %opt);
65 }
66  
67 21 1;
« Elive/Entity/Group.pm ↑ Summary Elive/Entity/User.pm »