File Coverage

blib/lib/Data/Toolkit/Connector.pm
Criterion Covered Total %
statement 27 33 81.8
branch 5 12 41.6
condition n/a
subroutine 7 8 87.5
pod 2 2 100.0
total 41 55 74.5


line stmt bran cond sub pod time code
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     3   97806 use strict;
  3         8  
  3         123  
14 3     3   3381 use Data::Dumper;
  3         34213  
  3         264  
15 3     3   29 use Carp;
  3         6  
  3         186  
16 3     3   2546 use Clone qw(clone);
  3         10448  
  3         263  
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     3   26 use vars qw($VERSION);
  3         5  
  3         765  
42             $VERSION = '1.0';
43              
44             # Set this non-zero for debug logging
45             #
46             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 3     3 1 7 my $class = shift;
64 3         7 my $configParam = shift;
65              
66 3         8 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 3 100       13 if (defined($configParam)) {
73 2 50       10 if ((ref $configParam) ne 'HASH') {
74 0         0 croak "Data::Toolkit::Connector->new expects a hash ref but was given something else"
75             }
76              
77 2         31 $self->{config} = clone($configParam);
78             }
79             else {
80             # Start with empty config
81 1         4 $self->{config} = {};
82             }
83              
84              
85 3         9 bless ($self, $class);
86              
87 3 50       14 carp "Data::Toolkit::Connector->new $self" if $debug;
88 3         10 return $self;
89             }
90              
91             sub DESTROY {
92 1     1   2 my $self = shift;
93 1 50       115 carp "Data::Toolkit::Connector Destroying $self" if $debug;
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     0 1   my $class = shift;
134 0 0         if (ref $class) { croak "Class method 'debug' called as object method" }
  0            
135             # print "DEBUG: ", (join '/', @_), "\n";
136 0 0         $debug = shift if (@_ == 1);
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             1;