| 1 | package Helios::ObjectDriver; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Helios::Config; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Helios::ObjectDriver::DBI; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Helios::Error; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Helios::Error::ObjectDriverError; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | 1 | our $VERSION = '2.80'; | |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | Helios::ObjectDriver - class to return Helios::ObjectDriver::DBI objects pointing to the collective database | ||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | # in code that needs a Helios::ObjectDriver::DBI object | ||||||||||||||||||||||||||||||||||
| 21 | my $driver = Helios::ObjectDriver->getDriver(); | ||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | # if the config parameters have already been parsed, | ||||||||||||||||||||||||||||||||||
| 24 | # save the trouble of reparsing them by passing the configuration | ||||||||||||||||||||||||||||||||||
| 25 | my $conf = Helios::Config->parseConfig(service_name => 'MyService'); | ||||||||||||||||||||||||||||||||||
| 26 | my $driver = Helios::ObjectDriver->getDriver(config => $conf); | ||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||
| 30 | The Helios::ObjectDriver class provides methods to create | ||||||||||||||||||||||||||||||||||
| 31 | Helios::ObjectDriver::DBI driver objects that connect to the Helios collective | ||||||||||||||||||||||||||||||||||
| 32 | database. Having this code in a central class reduces the amount of duplicated | ||||||||||||||||||||||||||||||||||
| 33 | code in various other Helios classes and provides a level of abstraction | ||||||||||||||||||||||||||||||||||
| 34 | between the Helios API classes and Data::ObjectDriver, the current ORM. | ||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||
| 36 | Like Helios::Config and Helios::Logger classes, Helios::ObjectDriver is not | ||||||||||||||||||||||||||||||||||
| 37 | designed to be instantiated and thus provides only class methods. | ||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | =head1 ACCESSOR METHODS | ||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | debug | ||||||||||||||||||||||||||||||||||
| 42 | set/getConfig | ||||||||||||||||||||||||||||||||||
| 43 | set/getDriver | ||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | =cut | ||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | 1 | my $Debug = 0; | |||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub debug { my $self = shift; @_ ? $Debug = shift : $Debug; } | ||||||||||||||||||||||||||||||||
|
Subroutine
debug: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | 1 | my $Config; | |||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub setConfig { | ||||||||||||||||||||||||||||||||
|
Subroutine
setConfig: not called CC=1 SCAR=0.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 52 | 0 | my $var = $_[0]."::Config"; | |||||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 54 | 0 | $$var = $_[1]; | |||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub getConfig { | ||||||||||||||||||||||||||||||||
|
Subroutine
getConfig: not called CC=1 SCAR=0.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 57 | 0 | my $var = $_[0]."::Config"; | |||||||||||||||||||||||||||||||||
| 58 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 59 | 0 | return $$var; | |||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||
| 62 | my $Driver; | ||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub setDriver { | ||||||||||||||||||||||||||||||||
|
Subroutine
setDriver: not called CC=1 SCAR=0.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 64 | 0 | my $var = $_[0]."::Driver"; | |||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 66 | 0 | $$var = $_[1]; | |||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub getDriver { | ||||||||||||||||||||||||||||||||
|
Subroutine
getDriver: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 70 | 0 | initDriver(@_); | |||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||
| 74 | =head2 initDriver([config => $config_hashref]) | ||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | The initDriver() method is the method that actually instantiates the driver | ||||||||||||||||||||||||||||||||||
| 77 | object connecting to the database. | ||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||
| 79 | If a config is specified, Helios::ObjectDriver will use the parameters in the | ||||||||||||||||||||||||||||||||||
| 80 | config hash to connect to the database and instantiate the driver object. If | ||||||||||||||||||||||||||||||||||
| 81 | config is not specified, initDriver() will call Helios::Config->parseConfig() | ||||||||||||||||||||||||||||||||||
| 82 | to (re)parse the current Helios configuration itself. If the Helios config has | ||||||||||||||||||||||||||||||||||
| 83 | been parsed already, specifying it in the initDriver() call will save some | ||||||||||||||||||||||||||||||||||
| 84 | time. | ||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | THROWS: Helios::Error::ObjectDriverError if the driver creation fails. | ||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | =cut | ||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub initDriver { | ||||||||||||||||||||||||||||||||
|
Subroutine
initDriver: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 91 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 92 | 0 | my %params = @_; | |||||||||||||||||||||||||||||||||
| 93 | 0 | my $conf; | |||||||||||||||||||||||||||||||||
| 94 | my $driver; | ||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||
| 96 | # handle config | ||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | $conf = $params{config} || $self->getConfig() || Helios::Config->parseConfig(); | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$params{'config'} || $self->getConfig || 'Helios::Config'->parseConfig
$params{"config"} or $self->getConfig
MC/DC0%0/3
$params{'config'} || $self->getConfig || 'Helios::Config'->parseConfig
$params{"config"}
$self->getConfig
'Helios::Config'->parseConfig
Truth table0%0/4
A or B || C
A= $params{"config"}B= $self->getConfigC= 'Helios::Config'->parseConfig
| |||||||||||||||||||||||||||||||||||
| 98 | 0 | $self->setConfig($conf); | |||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if ($self->debug) { print __PACKAGE__.'->initDriver('.$conf->{dsn}.','.$conf->{user}.")\n"; } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||
| 102 | eval { | ||||||||||||||||||||||||||||||||||
| 103 | $driver = Helios::ObjectDriver::DBI->new( | ||||||||||||||||||||||||||||||||||
| 104 | dsn => $conf->{dsn}, | ||||||||||||||||||||||||||||||||||
| 105 | username => $conf->{user}, | ||||||||||||||||||||||||||||||||||
| 106 | password => $conf->{password} | ||||||||||||||||||||||||||||||||||
| 107 | 0 | ); | |||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ($self->debug) { print __PACKAGE__.'->initDriver() DRIVER: ',$driver,"\n"; } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 109 | 0 | 1; | |||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | } or do { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 111 | 0 | my $E = $@; | |||||||||||||||||||||||||||||||||
| 112 | 0 | Helios::Error::ObjectDriverError->throw("$E"); | |||||||||||||||||||||||||||||||||
| 113 | }; | ||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||
| 115 | 0 | $self->setDriver($driver); | |||||||||||||||||||||||||||||||||
| 116 | 0 | return $driver; | |||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | 1 | 1; | |||||||||||||||||||||||||||||||||
| 122 | __END__ | ||||||||||||||||||||||||||||||||||