Toolkit/Connector.pm

filter: Statementstmt 83.3% 30 / 36 Branchbran 41.6% 5 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 100% 2 / 2 totaltotal 75.8% 44 / 58 SCAR 20.8
CC
7
Cov
73%
debug
12.0
new
4.1
DESTROY
2.1
CRAP 8.0
« Toolkit/Connector/CSV.pm ↑ Summary
1 #!/usr/bin/perl -w
2 #
3 # Data::Toolkit::Connector
4 #
5 # Andrew Findlay
6 # Nov 2006
7 # andrew.findlay@skills-1st.co.uk
8 #
9 # $Id: Connector.pm 388 2013-08-30 15:19:23Z remotesvn $
10  
11 package Data::Toolkit::Connector;
12  
13 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use Clone qw(clone);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 =head1 NAME
19  
20 Data::Toolkit::Connector
21  
22 =head1 DESCRIPTION
23  
24 Base class for objects that connect to data sources
25  
26 =head1 SYNOPSIS
27  
28  
29 =head1 DEPENDENCIES
30  
31 Carp
32 Clone
33 Data::Dumper
34  
35 =cut
36  
37 ########################################################################
38 # Package globals
39 ########################################################################
40  
41 3 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
42 3 $VERSION = '1.0';
43  
44 # Set this non-zero for debug logging
45 #
46 3 my $debug = 0;
47  
48 ########################################################################
49 # Constructors and destructors
50 ########################################################################
51  
52 =head1 Constructor
53  
54 =head2 new
55  
56 my $map = Data::Toolkit::Connector->new();
57  
58 Creates an object of type Data::Toolkit::Connector
59  
60 =cut
61  
62 sub new {
63 4 ▶ my $class = shift;
Subroutine new: called CC=4 SCAR=14.1
Pod documented
64 4 my $configParam = shift;
65  
66 4 my $self = {};
67  
68 # Take a copy of the config hash if we were given one
69 # - we don't want to store a ref to the one we were given
70 # in case it is part of another object
71 #
72 4 ▶ if (defined($configParam)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $configParam) { } 2 2 4
73 2 ▶ if ((ref $configParam) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $configParam ne "HASH") 0 2 2
74 0 croak "Data::Toolkit::Connector->new expects a hash ref but was given something else"
75 }
76  
77 2 $self->{config} = clone($configParam);
78 }
79 else {
80 # Start with empty config
81 2 $self->{config} = {};
82 }
83  
84  
85 4 bless ($self, $class);
86  
87 4 ▶ carp "Data::Toolkit::Connector->new $self" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 4 4
88 4 return $self;
89 }
90  
91 sub DESTROY {
92 1 ▶ my $self = shift;
Subroutine DESTROY: called CC=2 SCAR=7.2
93 1 ▶ carp "Data::Toolkit::Connector Destroying $self" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1 1
94 }
95  
96 ########################################################################
97 # Methods
98 ########################################################################
99  
100 =head1 Methods
101  
102 =cut
103  
104  
105 ########################################################################
106 # Debugging methods
107 ########################################################################
108  
109 =head1 Debugging methods
110  
111 =head2 debug
112  
113 Set and/or get the debug level for Data::Toolkit::Connector
114  
115 my $currentDebugLevel = Data::Toolkit::Connector->debug();
116 my $newDebugLevel = Data::Toolkit::Connector->debug(1);
117  
118 Any non-zero debug level causes the module to print copious debugging information.
119  
120 Note that this is a package method, not an object method. It should always be
121 called exactly as shown above.
122  
123 All debug information is reported using "carp" from the Carp module, so if
124 you want a full stack backtrace included you can run your program like this:
125  
126 perl -MCarp=verbose myProg
127  
128 =cut
129  
130 # Class method to set and/or get debug level
131 #
132 sub debug {
133 0 ▶ my $class = shift;
Subroutine debug: not called CC=3 SCAR=24.8
Pod documented
134 0 ▶ if (ref $class) { croak "Class method 'debug' called as object method" }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) 0 0 0
135 # print "DEBUG: ", (join '/', @_), "\n";
136 0 ▶ $debug = shift if (@_ == 1);
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
137 0 return $debug
138 }
139  
140  
141 ########################################################################
142 ########################################################################
143  
144 =head1 Author
145  
146 Andrew Findlay
147  
148 Skills 1st Ltd
149  
150 andrew.findlay@skills-1st.co.uk
151  
152 http://www.skills-1st.co.uk/
153  
154 =cut
155  
156 ########################################################################
157 ########################################################################
158 3 1;
« Toolkit/Connector/CSV.pm ↑ Summary