| 1 | package DBICx::Deploy; | ||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use File::Spec; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | our $VERSION = '0.02'; | |||||||||
| 8 | |||||||||||
| 9 | 2 | ▶ | sub deploy { | ||||||||
|
Subroutine
deploy: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||
| 10 | 2 | my ($class, $schema_class, $dsn, @args) = @_; | |||||||||
| 11 | 2 | ▶ | croak 'need schema' unless $schema_class; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 12 | 2 | ▶ | croak 'need dsn' unless $dsn; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 13 | |||||||||||
| 14 | 2 | ▶ | eval "require $schema_class" or die "Failed to use $schema_class: $@"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | |||||||||||
| 16 | 2 | ▶ | if($dsn =~ /^DBI:/i){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 1 | my $schema = $schema_class->connect($dsn, @args); | |||||||||
| 18 | 1 | $schema->deploy; | |||||||||
| 19 | } | ||||||||||
| 20 | else { | ||||||||||
| 21 | # $dsn is a directory | ||||||||||
| 22 | 1 | my $schema = $schema_class->connect; | |||||||||
| 23 | 1 | _mkdir($dsn); | |||||||||
| 24 | 1 | ▶ | @args = qw/MySQL SQLite PostgreSQL/ if !@args; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 1 | $schema->create_ddl_dir(\@args, undef, $dsn); | |||||||||
| 26 | } | ||||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | # wtf. why? | ||||||||||
| 30 | 1 | ▶ | sub _mkdir { | ||||||||
|
Subroutine
_mkdir: called CC=2 SCAR=6.9
| |||||||||||
| 31 | 1 | my $dir = shift; | |||||||||
| 32 | 1 | my @dirs = File::Spec->splitdir($dir); | |||||||||
| 33 | |||||||||||
| 34 | 1 | my $base = shift @dirs; | |||||||||
| 35 | 1 | mkdir $base; | |||||||||
| 36 | 1 | foreach my $d (@dirs){ | |||||||||
| 37 | 2 | $base = File::Spec->catdir($base, $d); | |||||||||
| 38 | 2 | mkdir $base; | |||||||||
| 39 | } | ||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 2 | 1; | |||||||||
| 43 | |||||||||||
| 44 | __END__ | ||||||||||