| 1 | package DBIx::Wizard; | ||||||||||
| 2 | |||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 11 | ▶ | use SQL::Wizard; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 11 | ▶ | use DBIx::Wizard::ResultSet; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 11 | ▶ | use DBIx::Wizard::DB; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 11 | ▶ | use Exporter 'import'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 11 | our $VERSION = '0.06'; | |||||||||
| 10 | 11 | our @EXPORT = qw(dbiw); | |||||||||
| 11 | |||||||||||
| 12 | 11 | my $sw = SQL::Wizard->new; | |||||||||
| 13 | 11 | my $default_inflate_class = 'Time::Moment'; | |||||||||
| 14 | |||||||||||
| 15 | 22 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=2 SCAR=7.0
| |||||||||||
| 16 | 22 | my $class = shift; | |||||||||
| 17 | |||||||||||
| 18 | # Pull out our options before passing to Exporter | ||||||||||
| 19 | 22 | my %opts = @_; | |||||||||
| 20 | 22 | ▶ | if ($opts{inflate_class}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 0 | $default_inflate_class = $opts{inflate_class}; | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | # Let Exporter handle @EXPORT | ||||||||||
| 25 | 22 | my $caller = caller; | |||||||||
| 26 | 11 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 22 | *{"${caller}::dbiw"} = \&dbiw; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 5 | ▶ | sub default_inflate_class { | ||||||||
|
Subroutine
default_inflate_class: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 31 | 5 | my ($class, $new) = @_; | |||||||||
| 32 | 5 | ▶ | $default_inflate_class = $new if defined $new; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 5 | return $default_inflate_class; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 92 | ▶ | sub dbiw { | ||||||||
|
Subroutine
dbiw: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 37 | # No args: return SQL::Wizard instance for expression building | ||||||||||
| 38 | 92 | ▶ | return $sw unless @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | |||||||||||
| 40 | 84 | my ($db, $table) = split /:/, shift; | |||||||||
| 41 | |||||||||||
| 42 | # No table: db-only, return DB wrapper for transactions etc. | ||||||||||
| 43 | 84 | ▶ | if (!$table) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 8 | return DBIx::Wizard::DB->wrapper($db); | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 76 | return DBIx::Wizard::ResultSet->new({ | |||||||||
| 48 | table => $table, | ||||||||||
| 49 | db => $db, | ||||||||||
| 50 | inflate => 1, | ||||||||||
| 51 | }); | ||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 11 | 1; | |||||||||