blib/lib/XAS/Singleton.pm

filter: Statementstmt 40.0% 8 / 20 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 40.0% 2 / 5 Podpod 100% 1 / 1 totaltotal 25.0% 11 / 44 CC 7 SCAR 27.6
CC
7
Cov
24%
_new_instance
30.0
new
6.8
__ANON__
2.0
CRAP 15.9
« blib/lib/XAS/Exception.pm ↑ Summary blib/lib/XAS/Lib/Service.pm »
1 package XAS::Singleton;
2  
3 1 our $VERSION = '0.01';
4  
5 use XAS::Class
6 1 debug => 0,
7 version => $VERSION,
8 base => 'XAS::Base',
9 constants => 'HASH',
10 1 ▶;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # ----------------------------------------------------------------------
13 # Here be the best of cut-and-paste programming. This combines
14 # the guts of Class::Singleton with Badger::Base to make singletons!
15 # ----------------------------------------------------------------------
16  
17 # ----------------------------------------------------------------------
18 # Public Methods
19 # ----------------------------------------------------------------------
20  
21 sub new {
22 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=19.2
Pod documented
23  
24 # already got an object
25  
26 0 ▶ return $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
27  
28 # we store the instance in the _instance variable in the $class package.
29  
30 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
31 0 my $instance = \${ "$class\::_instance" };
32  
33 0 ▶ defined $$instance
Branch: 1 branch
BranchTrueFalseTotal
defined $$instance ? : 0 0 0
34 ? $$instance
35 : ($$instance = $class->_new_instance(@_));
36  
37 }
38  
39 # ----------------------------------------------------------------------
40 # Private Methods
41 # ----------------------------------------------------------------------
42  
43 sub _new_instance {
44 0 ▶ my $class = shift;
Subroutine _new_instance: not called CC=5 SCAR=34.0
45  
46 # install warning handling for odd number of parameters when DEBUG enabled
47  
48 local $SIG{__WARN__} = sub {
49 0 ▶ Badger::Utils::odd_params(@_);
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 0 } if DEBUG;
51  
52 0 ▶ my $args = @_ && ref $_[0] eq HASH ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
@_ && ref $_[0] eq 'HASH' ? : 0 0 0
Condition0%0/3
@_ and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and ref $_[0] eq "HASH"
@_ ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= @_B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
53 0 ▶ my $self = bless { }, ref $class || $class;
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
54  
55 0 $self = $self->init($args);
56  
57 # be careful to account for object that overload the boolean comparison
58 # operator and may return false to a simple truth test.
59  
60 0 ▶ return defined $self
Branch: 1 branch
BranchTrueFalseTotal
defined $self ? : 0 0 0
61 ? $self
62 : $self->error("init() method failed\n");
63  
64 }
65  
66 1 1;
67  
68 __END__
69  
70 =head1 NAME
71  
72 XAS::Singleton - A singleton class for the XAS environment
73  
74 =head1 SYNOPSIS
75  
76 use XAS::Class
77 version => '0.01'
78 base => 'XAS::Singleton'
79 ;
80  
81 =head1 DESCRIPTION
82  
83 There can only be one... A singleton class for the XAS environment.
84  
85 =head1 METHODS
86  
87 =head2 new
88  
89 Initalize the class.
90  
91 =head1 SEE ALSO
92  
93 =over 4
94  
95 =item L<XAS|XAS>
96  
97 =back
98  
99 =head1 AUTHOR
100  
101 Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt>
102  
103 =head1 COPYRIGHT AND LICENSE
104  
105 Copyright (C) 2014 Kevin L. Esteb
106  
107 This is free software; you can redistribute it and/or modify it under
108 the terms of the Artistic License 2.0. For details, see the full text
109 of the license at http://www.perlfoundation.org/artistic_license_2_0.
110  
111 =cut
« blib/lib/XAS/Exception.pm ↑ Summary blib/lib/XAS/Lib/Service.pm »