lib/Egg/Helper/Model/DBIC.pm

filter: Statementstmt 25.9% 14 / 54 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 57.1% 4 / 7 Podpod n/a totaltotal 18.1% 18 / 99 CC 17 SCAR 50.6
CC
17
Cov
16%
_start_helper
240.0
_helper_help
12.0
_helper_get_options
2.0
CRAP 158.3
↑ Summary lib/Egg/Model/DBIC.pm »
1 package Egg::Helper::Model::DBIC;
2 #
3 # Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
4 #
5 # $Id: DBIC.pm 352 2008-07-14 13:26:41Z lushe $
6 #
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use UNIVERSAL::require;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use DBIx::Class::Schema::Loader qw/ make_schema_at /;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 our $VERSION= '3.00';
13  
14 0 ▶sub _start_helper {
Subroutine _start_helper: not called CC=15 SCAR=54.8
15 0 my($self)= @_;
16 0 my $c= $self->config;
17 0 my $project= $self->project_name;
18 0 ▶ $c->{helper_option}{project_root} || return $self->_helper_help
Branch: 1 branch
BranchTrueFalseTotal
$c->{"helper_option"}{"project_root"} or return $self->_helper_help("I want you to start from helper of the project.") 0 0 0
19 ('I want you to start from helper of the project.');
20 0 ▶ my $schema_name= ucfirst( shift( @ARGV ) )
Condition0%0/2
ucfirst shift @ARGV || (return $self->_helper_help('I want component name.'))
l!l
00
MC/DC0%0/1
ucfirst shift @ARGV || (return $self->_helper_help('I want component name.'))
ucfirst shift @ARGV
Truth table0%0/2
A
A= ucfirst shift @ARGV
Aresult
11
00
21 || return $self->_helper_help('I want component name.');
22 0 ▶ $schema_name=~m{^^[A-Z][A-Za-z0-9\_]+$}
Branch: 1 branch
BranchTrueFalseTotal
$schema_name =~ /^^[A-Z][A-Za-z0-9\_]+$/ or return $self->_helper_help("Bad schema name '${schema_name}'") 0 0 0
23 || return $self->_helper_help("Bad schema name '$schema_name'");
24 0 my $o= $self->_helper_get_options;
25 0 ▶ my $version= $self->helper_valid_version_number($o->{version}) || return 0;
Condition0%0/2
$self->helper_valid_version_number($o->{'version'}) || (return 0)
l!l
00
MC/DC0%0/1
$self->helper_valid_version_number($o->{'version'}) || (return 0)
$self->helper_valid_version_number($o->{'version'})
Truth table0%0/2
A
A= $self->helper_valid_version_number($o->{'version'})
Aresult
11
00
26 $o->{dsn}
27 0 ▶ || return $self->_helper_help(q{ '-d' Please give DSN by the option. });
Branch: 1 branch
BranchTrueFalseTotal
$o->{"dsn"} or return $self->_helper_help(" '-d' Please give DSN by the option. ") 0 0 0
28 0 ▶ $o->{user} ||= "";
Condition0%0/2
$o->{"user"} ||= ""
l!l
00
MC/DC0%0/1
$o->{"user"} ||= ""
$o->{"user"}
Truth table0%0/2
A
A= $o->{"user"}
Aresult
11
00
29 0 ▶ $o->{password} ||= "";
Condition0%0/2
$o->{"password"} ||= ""
l!l
00
MC/DC0%0/1
$o->{"password"} ||= ""
$o->{"password"}
Truth table0%0/2
A
A= $o->{"password"}
Aresult
11
00
30 0 ▶ $o->{dsn}.= ";host=$o->{host}" if $o->{host};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"host"} 0 0 0
31 0 ▶ $o->{dsn}.= ";port=$o->{inet_port}" if $o->{inet_port};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"inet_port"} 0 0 0
32 0 my $param= $self->helper_prepare_param({
33 module_version=> $version, dbi=> $o,
34 created=> __PACKAGE__. " v$VERSION",
35 });
36 0 $self->helper_prepare_param_module
37 ($param, $self->project_name, qw/ Model DBIC /, $schema_name);
38 0 my $lib_path = "$param->{output_path}/lib/$param->{module_basedir}";
39 0 my $schema_path= "$param->{output_path}/lib/$param->{module_filepath}";
40 0 ▶ unless (-e $lib_path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $lib_path) 0 0 0
41 0 $self->helper_create_dir($lib_path);
42 }
43 0 ▶ -e $schema_path
Branch: 1 branch
BranchTrueFalseTotal
-e $schema_path and return $self->_helper_help("'${schema_path}' already exists.") 0 0 0
44 and return $self->_helper_help("'$schema_path' already exists.");
45  
46 0 my $origin_code= <<END_CODE;
47 use base qw/ Egg::Model::DBIC::Schema /;
48  
49 __PACKAGE__->config(
50  
51 # label_name => 'mylabel',
52 # label_source => {
53 # moniker => 'mymoniker',
54 # },
55  
56 dsn => '$o->{dsn}',
57 user => '$o->{user}',
58 password => '$o->{password}',
59 options => {
60 AutoCommit => 1,
61 RaiseError => 1,
62 PrintError => 0,
63 },
64  
65 );
66 END_CODE
67  
68 0 ▶ $self->helper_chdir($c->{root}) || return
Branch: 1 branch
BranchTrueFalseTotal
$self->helper_chdir($c->{"root"}) or return $self->_helper_help("The root directory of the project cannot be changed.") 0 0 0
69 $self->_helper_help('The root directory of the project cannot be changed.');
70 0 eval {
71 make_schema_at("${project}::Model::DBIC::$schema_name", {
72 debug => ($o->{debug} || 0),
73 relationships => 1,
74 dump_directory => './lib',
75 },
76 0 ▶ [@{$o}{qw/ dsn user password /}],
Condition0%0/2
$o->{'debug'} || 0
l!l
00
MC/DC0%0/1
$o->{'debug'} || 0
$o->{'debug'}
Truth table0%0/2
A
A= $o->{'debug'}
Aresult
11
00
77 );
78 0 my $value= $self->helper_fread($schema_path);
79 0 $value=~s{\n+(use\s+base\s+[^\;]+\;)\s*} [\n# $1\n\n${origin_code}\n]s;
80 0 $self->helper_save_file( $schema_path => \$value );
81 };
82 0 ▶ if (my $err= $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) { } 0 0 0
83 0 $self->helper_remove_file($schema_path);
84 0 $schema_path=~s{\.pm$} [];
85 0 $self->helper_remove_dir($schema_path);
86 0 $self->_helper_help($err);
87 } else {
88 0 print <<END_INFO;
89 ... done.
90  
91 output of Schema: $schema_path
92  
93 END_INFO
94 }
95 }
96 0 ▶sub _helper_get_options {
Subroutine _helper_get_options: not called CC=1 SCAR=6.9
97 0 $_[0]->next::method
98 ('d-dsn= u-user= p-password= s-host= i-inet_port=');
99 }
100 0 ▶sub _helper_help {
Subroutine _helper_help: not called CC=3 SCAR=24.8
101 0 my $self= shift;
102 0 ▶ my $msg = shift || "";
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
103 0 ▶ $msg= "\nERROR: ${msg}\n\n" if $msg;
Branch: 1 branch
BranchTrueFalseTotal
if $msg 0 0 0
104 0 print <<END_HELP;
105 ${msg}% perl egg_helper.pl Model::DBIC [SCHEMA_NAME] [OPTIONS]
106  
107 OPTIONS: -d ... DSN.
108 -u ... DB_USER.
109 -p ... DB_PASSWORD.
110 -s ... DB_HOST.
111 -i ... DB_PORT.
112  
113 Usage:
114 0 % perl @{[ lc $self->project_name ]}\_helper.pl Model:DBIC MySchema \\
115 > -d dbi:Pg:dbname=mydb \\
116 > -u dbuser \\
117 > -p dbpassword
118  
119 END_HELP
120 }
121  
122 2 1;
123  
124 __END__
↑ Summary lib/Egg/Model/DBIC.pm »