| 1 | package Catalyst::Helper::Model::DBIC::Schema; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | our $VERSION = '0.66'; | |||||||||||||||||||||||||||
| 8 | 2 | $VERSION =~ tr/_//d; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Tie::IxHash (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Data::Dumper (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use List::Util 'first'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use MooseX::Types::Moose qw/Str HashRef Bool ArrayRef/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Catalyst::Model::DBIC::Schema::Types 'CreateOption'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use List::MoreUtils 'firstidx'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use Scalar::Util 'looks_like_number'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use File::Find 'finddepth'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use Cwd 'getcwd'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use Module::Runtime 'use_module'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 NAME | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | Catalyst::Helper::Model::DBIC::Schema - Helper for DBIC Schema Models | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | script/create.pl model CatalystModelName DBIC::Schema MyApp::SchemaClass \ | ||||||||||||||||||||||||||||
| 30 | [ create=dynamic | create=static ] [ traits=trait1,trait2... ] \ | ||||||||||||||||||||||||||||
| 31 | [ Schema::Loader opts ] [ dsn user pass ] \ | ||||||||||||||||||||||||||||
| 32 | [ other connect_info args ] | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | Helper for the DBIC Schema Models. | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =head2 Arguments: | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | C<CatalystModelName> is the short name for the Catalyst Model class | ||||||||||||||||||||||||||||
| 41 | being generated (i.e. callable with C<$c-E<gt>model('CatalystModelName')>). | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | C<MyApp::SchemaClass> is the fully qualified classname of your Schema, | ||||||||||||||||||||||||||||
| 44 | which might or might not yet exist. Note that you should have a good | ||||||||||||||||||||||||||||
| 45 | reason to create this under a new global namespace, otherwise use an | ||||||||||||||||||||||||||||
| 46 | existing top level namespace for your schema class. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | C<create=dynamic> instructs this Helper to generate the named Schema | ||||||||||||||||||||||||||||
| 49 | class for you, basing it on L<DBIx::Class::Schema::Loader> (which | ||||||||||||||||||||||||||||
| 50 | means the table information will always be dynamically loaded at | ||||||||||||||||||||||||||||
| 51 | runtime from the database). | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | C<create=static> instructs this Helper to generate the named Schema | ||||||||||||||||||||||||||||
| 54 | class for you, using L<DBIx::Class::Schema::Loader> in "one shot" | ||||||||||||||||||||||||||||
| 55 | mode to create a standard, manually-defined L<DBIx::Class::Schema> | ||||||||||||||||||||||||||||
| 56 | setup, based on what the Loader sees in your database at this moment. | ||||||||||||||||||||||||||||
| 57 | A Schema/Model pair generated this way will not require | ||||||||||||||||||||||||||||
| 58 | L<DBIx::Class::Schema::Loader> at runtime, and will not automatically | ||||||||||||||||||||||||||||
| 59 | adapt itself to changes in your database structure. You can edit | ||||||||||||||||||||||||||||
| 60 | the generated classes by hand to refine them. | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | C<traits> is the list of traits to apply to the model, see | ||||||||||||||||||||||||||||
| 63 | L<Catalyst::Model::DBIC::Schema> for details. | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | C<Schema::Loader opts> are documented in L<DBIx::Class::Schema::Loader::Base> | ||||||||||||||||||||||||||||
| 66 | and some examples are given in L</TYPICAL EXAMPLES> below. | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | C<connect_info> arguments are the same as what L<DBIx::Class::Schema/connect> | ||||||||||||||||||||||||||||
| 69 | expects, and are storage_type-specific. They are documented in | ||||||||||||||||||||||||||||
| 70 | L<DBIx::Class::Storage::DBI/connect_info>. For DBI-based storage, these | ||||||||||||||||||||||||||||
| 71 | arguments are the dsn, username, password, and connect options, respectively. | ||||||||||||||||||||||||||||
| 72 | These are optional for existing Schemas, but required if you use either of the | ||||||||||||||||||||||||||||
| 73 | C<create=> options. | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | username and password can be omitted for C<SQLite> dsns. | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | Use of either of the C<create=> options requires L<DBIx::Class::Schema::Loader>. | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head1 TYPICAL EXAMPLES | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | Use DBIx::Class::Schema::Loader to create a static DBIx::Class::Schema, | ||||||||||||||||||||||||||||
| 82 | and a Model which references it: | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | script/myapp_create.pl model CatalystModelName DBIC::Schema \ | ||||||||||||||||||||||||||||
| 85 | MyApp::SchemaClass create=static dbi:mysql:foodb myuname mypass | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | Same, with extra connect_info args | ||||||||||||||||||||||||||||
| 88 | user and pass can be omitted for sqlite, since they are always empty | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | script/myapp_create.pl model CatalystModelName DBIC::Schema \ | ||||||||||||||||||||||||||||
| 91 | MyApp::SchemaClass create=static dbi:SQLite:foo.db \ | ||||||||||||||||||||||||||||
| 92 | AutoCommit=1 cursor_class=DBIx::Class::Cursor::Cached \ | ||||||||||||||||||||||||||||
| 93 | on_connect_do='["select 1", "select 2"]' quote_names=1 | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | B<ON WINDOWS COMMAND LINES QUOTING RULES ARE DIFFERENT> | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | In C<cmd.exe> the above example would be: | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | script/myapp_create.pl model CatalystModelName DBIC::Schema \ | ||||||||||||||||||||||||||||
| 100 | MyApp::SchemaClass create=static dbi:SQLite:foo.db \ | ||||||||||||||||||||||||||||
| 101 | AutoCommit=1 cursor_class=DBIx::Class::Cursor::Cached \ | ||||||||||||||||||||||||||||
| 102 | on_connect_do="[\"select 1\", \"select 2\"]" quote_names=1 | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | Same, but with extra Schema::Loader args (separate multiple values by commas): | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | script/myapp_create.pl model CatalystModelName DBIC::Schema \ | ||||||||||||||||||||||||||||
| 107 | MyApp::SchemaClass create=static db_schema=foodb components=Foo,Bar \ | ||||||||||||||||||||||||||||
| 108 | exclude='^(wibble|wobble)$' moniker_map='{ foo => "FOO" }' \ | ||||||||||||||||||||||||||||
| 109 | dbi:Pg:dbname=foodb myuname mypass | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | Coderefs are also supported: | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | script/myapp_create.pl model CatalystModelName DBIC::Schema \ | ||||||||||||||||||||||||||||
| 114 | MyApp::SchemaClass create=static \ | ||||||||||||||||||||||||||||
| 115 | inflect_singular='sub { $_[0] =~ /\A(.+?)(_id)?\z/; $1 }' \ | ||||||||||||||||||||||||||||
| 116 | moniker_map='sub { join(q{}, map ucfirst, split(/[\W_]+/, lc $_[0])); }' \ | ||||||||||||||||||||||||||||
| 117 | dbi:mysql:foodb myuname mypass | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | See L<DBIx::Class::Schema::Loader::Base> for a list of options | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | Create a dynamic DBIx::Class::Schema::Loader-based Schema, | ||||||||||||||||||||||||||||
| 122 | and a Model which references it (B<DEPRECATED>): | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | script/myapp_create.pl model CatalystModelName DBIC::Schema \ | ||||||||||||||||||||||||||||
| 125 | MyApp::SchemaClass create=dynamic dbi:mysql:foodb myuname mypass | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | Reference an existing Schema of any kind, and provide some connection information for ->config: | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | script/myapp_create.pl model CatalystModelName DBIC::Schema \ | ||||||||||||||||||||||||||||
| 130 | MyApp::SchemaClass dbi:mysql:foodb myuname mypass | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | Same, but don't supply connect information yet (you'll need to do this | ||||||||||||||||||||||||||||
| 133 | in your app config, or [not recommended] in the schema itself). | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | script/myapp_create.pl model ModelName DBIC::Schema My::SchemaClass | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | =cut | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 2 | has helper => (is => 'ro', isa => 'Catalyst::Helper', required => 1); | |||||||||||||||||||||||||||
| 140 | 2 | has create => (is => 'rw', isa => CreateOption); | |||||||||||||||||||||||||||
| 141 | 2 | has args => (is => 'ro', isa => ArrayRef); | |||||||||||||||||||||||||||
| 142 | 2 | has traits => (is => 'rw', isa => ArrayRef); | |||||||||||||||||||||||||||
| 143 | 2 | has schema_class => (is => 'ro', isa => Str, required => 1); | |||||||||||||||||||||||||||
| 144 | 2 | has loader_args => (is => 'rw', isa => HashRef); | |||||||||||||||||||||||||||
| 145 | 2 | has connect_info => (is => 'rw', isa => HashRef); | |||||||||||||||||||||||||||
| 146 | 2 | has old_schema => (is => 'rw', isa => Bool, lazy_build => 1); | |||||||||||||||||||||||||||
| 147 | 2 | has is_moose_schema => (is => 'rw', isa => Bool, lazy_build => 1); | |||||||||||||||||||||||||||
| 148 | 2 | has result_namespace => (is => 'rw', isa => Str, lazy_build => 1); | |||||||||||||||||||||||||||
| 149 | 2 | has components => (is => 'rw', isa => ArrayRef); | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =head1 METHODS | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =head2 mk_compclass | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | This is called by L<Catalyst::Helper> with the commandline args to generate the | ||||||||||||||||||||||||||||
| 156 | files. | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =cut | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | sub mk_compclass { | ||||||||||||||||||||||||||
|
Subroutine
mk_compclass: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 161 | 0 | my ($package, $helper, $schema_class, @args) = @_; | |||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | my $self = $package->new( | |||||||||||||||||||||||||||
| 164 | helper => $helper, | ||||||||||||||||||||||||||||
| 165 | schema_class => $schema_class, | ||||||||||||||||||||||||||||
| 166 | args => \@args | ||||||||||||||||||||||||||||
| 167 | ); | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | $self->run; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 173 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 174 | 0 | my $helper = $self->helper; | |||||||||||||||||||||||||||
| 175 | 0 | ▶ | my @args = @{ $self->args || [] }; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->args || []
MC/DC0%0/1
$self->args || []
$self->args
Truth table0%0/2
A
A= $self->args
| |||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | $helper->{schema_class} = $self->schema_class; | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 0 | @args = $self->_cleanup_args(\@args); | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 0 | my ($traits_idx, $traits); | |||||||||||||||||||||||||||
| 182 | 0 | ▶ | if (($traits_idx = firstidx { ($traits) = /^traits=(\S*)\z/ } @args) != -1) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 0 | my @traits = split /,/ => $traits; | |||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 0 | $self->traits(\@traits); | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | $helper->{traits} = '[' | ||||||||||||||||||||||||||||
| 188 | 0 | .(join ',' => map { qq{'$_'} } @traits) | |||||||||||||||||||||||||||
| 189 | .']'; | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | splice @args, $traits_idx, 1, (); | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 0 | ▶ | if ($args[0] && $args[0] =~ /^create=(\S*)\z/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args[0] and $args[0] =~ /^create=(\S*)\z/
MC/DC0%0/2
$args[0] and $args[0] =~ /^create=(\S*)\z/
$args[0]
$args[0] =~ /^create=(\S*)\z/
Truth table0%0/3
A and B
A= $args[0]B= $args[0] =~ /^create=(\S*)\z/
| |||||||||||||||||||||||||||||
| 195 | 0 | $self->create($1); | |||||||||||||||||||||||||||
| 196 | 0 | shift @args; | |||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 0 | ▶ | if (@args) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | 0 | $self->_parse_loader_args(\@args); | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 0 | $helper->{loader_args} = $self->_build_helper_loader_args; | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 0 | my $dbi_dsn_part; | |||||||||||||||||||||||||||
| 206 | 0 | ▶ | if (first { ($dbi_dsn_part) = /^(dbi):/i } @args) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | 0 | ▶ | die | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | qq{DSN must start with 'dbi:' not '$dbi_dsn_part' (case matters!)} | ||||||||||||||||||||||||||||
| 209 | if $dbi_dsn_part ne 'dbi'; | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 0 | $helper->{setup_connect_info} = 1; | |||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | $helper->{connect_info} = | ||||||||||||||||||||||||||||
| 214 | 0 | $self->_build_helper_connect_info(\@args); | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 0 | $self->_parse_connect_info(\@args); | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 0 | $helper->{generator} = ref $self; | |||||||||||||||||||||||||||
| 220 | 0 | $helper->{generator_version} = $VERSION; | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | =head2 run | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | Can be called on an instance to generate the files. | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | =cut | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 230 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 0 | ▶ | if ($self->create eq 'dynamic') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 233 | 0 | $self->_print_dynamic_deprecation_warning; | |||||||||||||||||||||||||||
| 234 | 0 | $self->_gen_dynamic_schema; | |||||||||||||||||||||||||||
| 235 | } elsif ($self->create eq 'static') { | ||||||||||||||||||||||||||||
| 236 | 0 | $self->_gen_static_schema; | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 0 | $self->_gen_model; | |||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 0 | ▶ | sub _parse_loader_args { | ||||||||||||||||||||||||||
|
Subroutine
_parse_loader_args: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||
| 243 | 0 | my ($self, $args) = @_; | |||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 0 | my %loader_args = $self->_read_loader_args($args); | |||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 0 | ▶ | while (my ($key, $val) = each %loader_args) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 248 | 0 | ▶ | next if $key =~ /^(?:components|constraint|exclude)\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 0 | $loader_args{$key} = $self->_eval($val); | |||||||||||||||||||||||||||
| 251 | 0 | ▶ | die "syntax error for loader args key '$key' with value '$val': $@" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | if $@; | ||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | my @components = $self->_build_loader_components( | ||||||||||||||||||||||||||||
| 256 | delete $loader_args{components}, | ||||||||||||||||||||||||||||
| 257 | $loader_args{use_namespaces}, | ||||||||||||||||||||||||||||
| 258 | 0 | ); | |||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 0 | $self->components(\@components); | |||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 0 | for my $re_opt (qw/constraint exclude/) { | |||||||||||||||||||||||||||
| 263 | $loader_args{$re_opt} = qr/$loader_args{$re_opt}/ | ||||||||||||||||||||||||||||
| 264 | 0 | ▶ | if exists $loader_args{$re_opt}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 0 | tie my %result, 'Tie::IxHash'; | |||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 0 | ▶ | %result = ( | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 270 | relationships => 1, | ||||||||||||||||||||||||||||
| 271 | use_moose => $self->is_moose_schema ? 1 : 0, | ||||||||||||||||||||||||||||
| 272 | col_collision_map => 'column_%s', | ||||||||||||||||||||||||||||
| 273 | (!$self->old_schema ? ( | ||||||||||||||||||||||||||||
| 274 | use_namespaces => 1 | ||||||||||||||||||||||||||||
| 275 | ) : ()), | ||||||||||||||||||||||||||||
| 276 | (@components ? ( | ||||||||||||||||||||||||||||
| 277 | components => \@components | ||||||||||||||||||||||||||||
| 278 | ) : ()), | ||||||||||||||||||||||||||||
| 279 | (%loader_args ? %loader_args : ()), | ||||||||||||||||||||||||||||
| 280 | ); | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 0 | $self->loader_args(\%result); | |||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 0 | ▶ | wantarray ? %result : \%result; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | 0 | ▶ | sub _read_loader_args { | ||||||||||||||||||||||||||
|
Subroutine
_read_loader_args: not called CC=16 SCAR=56.1
| |||||||||||||||||||||||||||||
| 288 | 0 | my ($self, $args) = @_; | |||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | 0 | my %loader_args; | |||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 0 | ▶ | while (@$args && $args->[0] !~ /^dbi:/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@$args and not $args->[0] =~ /^dbi:/i
MC/DC0%0/2
@$args and not $args->[0] =~ /^dbi:/i
@$args
not $args->[0] =~ /^dbi:/i
Truth table0%0/3
A and not(B)
A= @$argsB= not $args->[0] =~ /^dbi:/i
| |||||||||||||||||||||||||||||
| 293 | 0 | my ($key, $val) = split /=/, shift(@$args), 2; | |||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 0 | ▶ | if ($self->_is_struct($val)) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 296 | 0 | $loader_args{$key} = $val; | |||||||||||||||||||||||||||
| 297 | } elsif ((my @vals = split /,/ => $val) > 1) { | ||||||||||||||||||||||||||||
| 298 | 0 | $loader_args{$key} = \@vals; | |||||||||||||||||||||||||||
| 299 | } else { | ||||||||||||||||||||||||||||
| 300 | 0 | $loader_args{$key} = $val; | |||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | # Use args after connect_info as loader args as well, because people always | ||||||||||||||||||||||||||||
| 305 | # get the order confused. | ||||||||||||||||||||||||||||
| 306 | 0 | my $i = 1; | |||||||||||||||||||||||||||
| 307 | 0 | ▶ | if ($args->[0] =~ /sqlite/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 308 | 0 | ▶ | $i++ if $args->[$i] eq ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | 0 | ▶ | $i++ if $args->[$i] eq ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||
| 311 | else { | ||||||||||||||||||||||||||||
| 312 | 0 | $i += 2; | |||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | 0 | ▶ | my $have_loader = try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 316 | 0 | use_module('DBIx::Class::Schema::Loader::Base'); | |||||||||||||||||||||||||||
| 317 | 0 | 1; | |||||||||||||||||||||||||||
| 318 | 0 | }; | |||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | 0 | ▶ | if ($have_loader) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 321 | 0 | ▶ | while (defined $args->[$i]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 322 | 0 | ▶ | $i++ while $self->_is_struct($args->[$i]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 0 | ▶ | last if not defined $args->[$i]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | 0 | my ($key, $val) = split /=/, $args->[$i], 2; | |||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | 0 | ▶ | if (not DBIx::Class::Schema::Loader::Base->can($key)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 329 | 0 | $i++; | |||||||||||||||||||||||||||
| 330 | 0 | next; | |||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 0 | ▶ | if ($self->_is_struct($val)) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 334 | 0 | $loader_args{$key} = $val; | |||||||||||||||||||||||||||
| 335 | } elsif ((my @vals = split /,/ => $val) > 1) { | ||||||||||||||||||||||||||||
| 336 | 0 | $loader_args{$key} = \@vals; | |||||||||||||||||||||||||||
| 337 | } else { | ||||||||||||||||||||||||||||
| 338 | 0 | $loader_args{$key} = $val; | |||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | 0 | splice @$args, $i, 1; | |||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 0 | ▶ | wantarray ? %loader_args : \%loader_args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | 0 | ▶ | sub _build_helper_loader_args { | ||||||||||||||||||||||||||
|
Subroutine
_build_helper_loader_args: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 349 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | 0 | my $args = $self->loader_args; | |||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 0 | tie my %loader_args, 'Tie::IxHash'; | |||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | 0 | ▶ | while (my ($arg, $val) = each %$args) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 356 | 0 | ▶ | if (ref $val) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 357 | 0 | $loader_args{$arg} = $self->_data_struct_to_string($val); | |||||||||||||||||||||||||||
| 358 | } else { | ||||||||||||||||||||||||||||
| 359 | 0 | $loader_args{$arg} = qq{'$val'}; | |||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | 0 | \%loader_args | |||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | 0 | ▶ | sub _build_loader_components { | ||||||||||||||||||||||||||
|
Subroutine
_build_loader_components: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 367 | 0 | my ($self, $components, $use_namespaces) = @_; | |||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 0 | ▶ | my @components = $self->old_schema && (not $use_namespaces) ? () | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->old_schema and not $use_namespaces
MC/DC0%0/2
$self->old_schema and not $use_namespaces
$self->old_schema
not $use_namespaces
Truth table0%0/3
A and not(B)
A= $self->old_schemaB= not $use_namespaces
| |||||||||||||||||||||||||||||
| 370 | : ('InflateColumn::DateTime'); | ||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | 0 | ▶ | if ($components) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 373 | 0 | ▶ | $components = [ $components ] if !ref $components; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 374 | 0 | push @components, @$components; | |||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | 0 | ▶ | wantarray ? @components : \@components; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | 0 | ▶ | sub _build_helper_connect_info { | ||||||||||||||||||||||||||
|
Subroutine
_build_helper_connect_info: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 381 | 0 | my ($self, $connect_info) = @_; | |||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | 0 | my @connect_info = @$connect_info; | |||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | 0 | my ($dsn, $user, $password) = $self->_get_dsn_user_pass(\@connect_info); | |||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | 0 | tie my %helper_connect_info, 'Tie::IxHash'; | |||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | 0 | %helper_connect_info = ( | |||||||||||||||||||||||||||
| 390 | dsn => qq{'$dsn'}, | ||||||||||||||||||||||||||||
| 391 | user => qq{'$user'}, | ||||||||||||||||||||||||||||
| 392 | password => qq{'$password'} | ||||||||||||||||||||||||||||
| 393 | ); | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | 0 | for (@connect_info) { | |||||||||||||||||||||||||||
| 396 | 0 | ▶ | if (/^\s*{.*}\s*\z/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 397 | 0 | my $hash = $self->_eval($_); | |||||||||||||||||||||||||||
| 398 | 0 | ▶ | die "Syntax errorr in connect_info hash: $_: $@" if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 399 | 0 | my %hash = %$hash; | |||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | 0 | for my $key (keys %hash) { | |||||||||||||||||||||||||||
| 402 | 0 | my $val = $hash{$key}; | |||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | 0 | ▶ | if (ref $val) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 405 | 0 | $val = $self->_data_struct_to_string($val); | |||||||||||||||||||||||||||
| 406 | } else { | ||||||||||||||||||||||||||||
| 407 | 0 | $val = $self->_quote($val); | |||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | 0 | $helper_connect_info{$key} = $val; | |||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | 0 | next; | |||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | 0 | my ($key, $val) = split /=/, $_, 2; | |||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | 0 | ▶ | if ($key eq 'quote_char') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 419 | 0 | ▶ | $helper_connect_info{$key} = length($val) == 1 ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 420 | $self->_quote($val) : | ||||||||||||||||||||||||||||
| 421 | $self->_data_struct_to_string([split //, $val]); | ||||||||||||||||||||||||||||
| 422 | } else { | ||||||||||||||||||||||||||||
| 423 | 0 | $helper_connect_info{$key} = $self->_quote_unless_struct($val); | |||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | 0 | \%helper_connect_info | |||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | 0 | ▶ | sub _build_old_schema { | ||||||||||||||||||||||||||
|
Subroutine
_build_old_schema: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 431 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | 0 | ▶ | return $self->result_namespace eq '' ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | 0 | ▶ | sub _build_is_moose_schema { | ||||||||||||||||||||||||||
|
Subroutine
_build_is_moose_schema: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 437 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | 0 | my @schema_parts = split '::', $self->schema_class; | |||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | my $result_dir = File::Spec->catfile( | ||||||||||||||||||||||||||||
| 442 | 0 | $self->helper->{base}, 'lib', @schema_parts, $self->result_namespace | |||||||||||||||||||||||||||
| 443 | ); | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | # assume yes for new schemas | ||||||||||||||||||||||||||||
| 446 | 0 | ▶ | return 1 if not -d $result_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | 0 | my $uses_moose = 1; | |||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | 0 | my $cwd = getcwd; | |||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | 0 | ▶ | try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 453 | 0 | ▶ | finddepth(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 454 | 0 | ▶ | return if $File::Find::name !~ /\.pm\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | 0 | ▶ | open my $fh, '<', $File::Find::name | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 457 | or die "Could not open $File::Find::name: $!"; | ||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | 0 | my $code = do { local $/; <$fh> }; | |||||||||||||||||||||||||||
| 460 | 0 | close $fh; | |||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | 0 | ▶ | $uses_moose = 0 if $code !~ /\nuse Moose;\n/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | 0 | die; | |||||||||||||||||||||||||||
| 465 | 0 | }, $result_dir); | |||||||||||||||||||||||||||
| 466 | 0 | }; | |||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | 0 | chdir $cwd; | |||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | 0 | return $uses_moose; | |||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | 0 | ▶ | sub _build_result_namespace { | ||||||||||||||||||||||||||
|
Subroutine
_build_result_namespace: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 474 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | 0 | my @schema_parts = split '::', $self->schema_class; | |||||||||||||||||||||||||||
| 477 | my $schema_pm = | ||||||||||||||||||||||||||||
| 478 | 0 | File::Spec->catfile($self->helper->{base}, 'lib', @schema_parts) . '.pm'; | |||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||
| 480 | 0 | ▶ | if (not -f $schema_pm) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 481 | 0 | eval { use_module('DBIx::Class::Schema::Loader') }; | |||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | 0 | ▶ | return 'Result' if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | 0 | ▶ | return (try { DBIx::Class::Schema::Loader->VERSION('0.05') }) ? 'Result' : ''; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||
| 488 | 0 | ▶ | open my $fh, '<', $schema_pm or die "Could not open $schema_pm: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 489 | 0 | my $code = do { local $/; <$fh> }; | |||||||||||||||||||||||||||
| 490 | 0 | close $fh; | |||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | 0 | my ($result_namespace) = $code =~ /result_namespace => '([^']+)'/; | |||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||
| 494 | 0 | ▶ | return $result_namespace if $result_namespace; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||
| 496 | 0 | ▶ | return '' if $code =~ /->load_classes/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | 0 | return 'Result'; | |||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | 0 | ▶ | sub _data_struct_to_string { | ||||||||||||||||||||||||||
|
Subroutine
_data_struct_to_string: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 502 | 0 | my ($self, $data) = @_; | |||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | 0 | local $Data::Dumper::Terse = 1; | |||||||||||||||||||||||||||
| 505 | 0 | local $Data::Dumper::Quotekeys = 0; | |||||||||||||||||||||||||||
| 506 | 0 | local $Data::Dumper::Sortkeys = 1; | |||||||||||||||||||||||||||
| 507 | 0 | local $Data::Dumper::Indent = 0; | |||||||||||||||||||||||||||
| 508 | 0 | local $Data::Dumper::Useqq = 1; | |||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||
| 510 | 0 | return Data::Dumper->Dump([$data]); | |||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | 0 | ▶ | sub _get_dsn_user_pass { | ||||||||||||||||||||||||||
|
Subroutine
_get_dsn_user_pass: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 514 | 0 | my ($self, $connect_info) = @_; | |||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||
| 516 | 0 | my $dsn = shift @$connect_info; | |||||||||||||||||||||||||||
| 517 | 0 | my ($user, $password); | |||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||
| 519 | 0 | ▶ | if ($dsn =~ /sqlite/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 520 | 0 | ($user, $password) = ('', ''); | |||||||||||||||||||||||||||
| 521 | 0 | ▶ | shift @$connect_info while @$connect_info and $connect_info->[0] eq ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@$connect_info and $connect_info->[0] eq ""
MC/DC0%0/2
@$connect_info and $connect_info->[0] eq ""
@$connect_info
$connect_info->[0] eq ""
Truth table0%0/3
A and B
A= @$connect_infoB= $connect_info->[0] eq ""
| |||||||||||||||||||||||||||||
| 522 | } else { | ||||||||||||||||||||||||||||
| 523 | 0 | ($user, $password) = splice @$connect_info, 0, 2; | |||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | 0 | ($dsn, $user, $password) | |||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||
| 529 | 0 | ▶ | sub _parse_connect_info { | ||||||||||||||||||||||||||
|
Subroutine
_parse_connect_info: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 530 | 0 | my ($self, $connect_info) = @_; | |||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||
| 532 | 0 | my @connect_info = @$connect_info; | |||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | 0 | my ($dsn, $user, $password) = $self->_get_dsn_user_pass(\@connect_info); | |||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | 0 | tie my %connect_info, 'Tie::IxHash'; | |||||||||||||||||||||||||||
| 537 | 0 | @connect_info{qw/dsn user password/} = ($dsn, $user, $password); | |||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||
| 539 | 0 | for (@connect_info) { | |||||||||||||||||||||||||||
| 540 | 0 | ▶ | if (/^\s*{.*}\s*\z/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 541 | 0 | my $hash = $self->_eval($_); | |||||||||||||||||||||||||||
| 542 | 0 | ▶ | die "Syntax errorr in connect_info hash: $_: $@" if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||
| 544 | 0 | %connect_info = (%connect_info, %$hash); | |||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | 0 | next; | |||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||
| 549 | 0 | my ($key, $val) = split /=/, $_, 2; | |||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||
| 551 | 0 | ▶ | if ($key eq 'quote_char') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 552 | 0 | ▶ | $connect_info{$key} = length($val) == 1 ? $val : [split //, $val]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 553 | } elsif ($key =~ /^(?:name_sep|limit_dialect)\z/) { | ||||||||||||||||||||||||||||
| 554 | 0 | $connect_info{$key} = $val; | |||||||||||||||||||||||||||
| 555 | } else { | ||||||||||||||||||||||||||||
| 556 | 0 | $connect_info{$key} = $self->_eval($val); | |||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||
| 559 | 0 | ▶ | die "syntax error for connect_info key '$key' with value '$val': $@" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 560 | if $@; | ||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||
| 563 | 0 | $self->connect_info(\%connect_info); | |||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||
| 565 | 0 | \%connect_info | |||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||
| 568 | 0 | ▶ | sub _is_struct { | ||||||||||||||||||||||||||
|
Subroutine
_is_struct: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 569 | 0 | my ($self, $val) = @_; | |||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||
| 571 | 0 | return $val =~ /^\s*(?:sub|[[{])/; | |||||||||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||
| 574 | 0 | ▶ | sub _quote { | ||||||||||||||||||||||||||
|
Subroutine
_quote: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 575 | 0 | my ($self, $val) = @_; | |||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||
| 577 | 0 | return 'q{'.$val.'}'; | |||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||
| 580 | 0 | ▶ | sub _quote_unless_struct { | ||||||||||||||||||||||||||
|
Subroutine
_quote_unless_struct: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 581 | 0 | my ($self, $val) = @_; | |||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | 0 | ▶ | $val = $self->_quote($val) if not $self->_is_struct($val); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||
| 585 | 0 | return $val; | |||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||
| 588 | 0 | ▶ | sub _eval { | ||||||||||||||||||||||||||
|
Subroutine
_eval: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 589 | 0 | my ($self, $code) = @_; | |||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||
| 591 | 0 | ▶ | return $code if looks_like_number $code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||
| 593 | 0 | ▶ | return $code if not $self->_is_struct($code); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||
| 595 | 0 | return eval "{no strict; $code}"; | |||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||
| 598 | 0 | ▶ | sub _gen_dynamic_schema { | ||||||||||||||||||||||||||
|
Subroutine
_gen_dynamic_schema: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 599 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||
| 601 | 0 | my $helper = $self->helper; | |||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||
| 603 | 0 | my @schema_parts = split(/\:\:/, $self->schema_class); | |||||||||||||||||||||||||||
| 604 | 0 | my $schema_file_part = pop @schema_parts; | |||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||
| 606 | my $schema_dir = File::Spec->catfile( | ||||||||||||||||||||||||||||
| 607 | 0 | $helper->{base}, 'lib', @schema_parts | |||||||||||||||||||||||||||
| 608 | ); | ||||||||||||||||||||||||||||
| 609 | 0 | my $schema_file = File::Spec->catfile( | |||||||||||||||||||||||||||
| 610 | $schema_dir, $schema_file_part . '.pm' | ||||||||||||||||||||||||||||
| 611 | ); | ||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||
| 613 | 0 | $helper->mk_dir($schema_dir); | |||||||||||||||||||||||||||
| 614 | 0 | $helper->render_file('schemaclass', $schema_file); | |||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||
| 617 | 0 | ▶ | sub _gen_static_schema { | ||||||||||||||||||||||||||
|
Subroutine
_gen_static_schema: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 618 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||
| 620 | 0 | ▶ | die "cannot load schema without connect info" unless $self->connect_info; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||
| 622 | 0 | my $helper = $self->helper; | |||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||
| 624 | 0 | my $schema_dir = File::Spec->catfile($helper->{base}, 'lib'); | |||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||
| 626 | 0 | ▶ | try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 627 | 0 | use_module('DBIx::Class::Schema::Loader') | |||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||
| 629 | 0 | ▶ | catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 630 | 0 | die "Cannot load DBIx::Class::Schema::Loader: $_"; | |||||||||||||||||||||||||||
| 631 | 0 | }; | |||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||
| 633 | 0 | DBIx::Class::Schema::Loader->import( | |||||||||||||||||||||||||||
| 634 | "dump_to_dir:$schema_dir", 'make_schema_at' | ||||||||||||||||||||||||||||
| 635 | ); | ||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||
| 637 | 0 | make_schema_at( | |||||||||||||||||||||||||||
| 638 | $self->schema_class, | ||||||||||||||||||||||||||||
| 639 | $self->loader_args, | ||||||||||||||||||||||||||||
| 640 | [$self->connect_info] | ||||||||||||||||||||||||||||
| 641 | ); | ||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||
| 643 | 0 | require lib; | |||||||||||||||||||||||||||
| 644 | 0 | lib->import($schema_dir); | |||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||
| 646 | 0 | use_module($self->schema_class); | |||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||
| 648 | 0 | my @sources = $self->schema_class->sources; | |||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||
| 650 | 0 | ▶ | if (not @sources) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 651 | 0 | warn <<'EOF'; | |||||||||||||||||||||||||||
| 652 | WARNING: No tables found, did you forget to specify db_schema? | ||||||||||||||||||||||||||||
| 653 | EOF | ||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||
| 657 | 0 | ▶ | sub _gen_model { | ||||||||||||||||||||||||||
|
Subroutine
_gen_model: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 658 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 659 | 0 | my $helper = $self->helper; | |||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||
| 661 | 0 | $helper->render_file('compclass', $helper->{file} ); | |||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||
| 664 | 0 | ▶ | sub _print_dynamic_deprecation_warning { | ||||||||||||||||||||||||||
|
Subroutine
_print_dynamic_deprecation_warning: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 665 | 0 | warn <<EOF; | |||||||||||||||||||||||||||
| 666 | ************************************ WARNING ********************************** | ||||||||||||||||||||||||||||
| 667 | * create=dynamic is DEPRECATED, please use create=static instead. * | ||||||||||||||||||||||||||||
| 668 | ******************************************************************************* | ||||||||||||||||||||||||||||
| 669 | EOF | ||||||||||||||||||||||||||||
| 670 | 0 | print "Continue? [y/n]: "; | |||||||||||||||||||||||||||
| 671 | 0 | chomp(my $response = <STDIN>); | |||||||||||||||||||||||||||
| 672 | 0 | ▶ | exit 0 if $response =~ /^n(o)?\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||
| 675 | 0 | ▶ | sub _cleanup_args { | ||||||||||||||||||||||||||
|
Subroutine
_cleanup_args: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 676 | 0 | my ($self, $args) = @_; | |||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||
| 678 | # remove blanks, ie. someoned doing foo \ bar | ||||||||||||||||||||||||||||
| 679 | 0 | my @res = grep !/^\s+\z/, @$args; | |||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||
| 681 | # remove leading whitespace, ie. foo \ bar | ||||||||||||||||||||||||||||
| 682 | 0 | s/^\s*// for @res; | |||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||
| 684 | @res | ||||||||||||||||||||||||||||
| 685 | 0 | } | |||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||
| 687 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||
| 689 | General Catalyst Stuff: | ||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||
| 691 | L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>, | ||||||||||||||||||||||||||||
| 692 | L<Catalyst::Response>, L<Catalyst::Helper>, L<Catalyst>, | ||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||
| 694 | Stuff related to DBIC and this Model style: | ||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||
| 696 | L<DBIx::Class>, L<DBIx::Class::Schema>, | ||||||||||||||||||||||||||||
| 697 | L<DBIx::Class::Schema::Loader>, L<Catalyst::Model::DBIC::Schema> | ||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||
| 699 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||
| 701 | See L<Catalyst::Model::DBIC::Schema/AUTHOR> and | ||||||||||||||||||||||||||||
| 702 | L<Catalyst::Model::DBIC::Schema/CONTRIBUTORS>. | ||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||
| 704 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||
| 706 | See L<Catalyst::Model::DBIC::Schema/COPYRIGHT>. | ||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||
| 708 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||
| 710 | This library is free software, you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 711 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||
| 713 | =cut | ||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||
| 715 | 2 | 1; | |||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||
| 717 | __DATA__ | ||||||||||||||||||||||||||||