« blib/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm
↑ Summary
blib/lib/DBIx/Class/Schema/Loader/DBI/Component/QuotedDefault.pm »
| 1 | package DBIx::Class::Schema::Loader; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 55 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 55 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 55 | ▶ | use base qw/DBIx::Class::Schema Class::Accessor::Grouped/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 55 | ▶ | use MRO::Compat; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 55 | ▶ | use mro 'c3'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 55 | ▶ | use Carp::Clan qw/^DBIx::Class/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 55 | ▶ | use Scalar::Util 'weaken'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 55 | ▶ | use Sub::Util 'set_subname'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 55 | ▶ | use DBIx::Class::Schema::Loader::Utils qw/array_eq sigwarn_silencer/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 55 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 55 | ▶ | use curry; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 55 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # Always remember to do all digits for the version even if they're 0 | ||||||||||||||||||||||||||||
| 17 | # i.e. first release of 0.XX *must* be 0.XX000. This avoids fBSD ports | ||||||||||||||||||||||||||||
| 18 | # brain damage and presumably various other packaging systems too | ||||||||||||||||||||||||||||
| 19 | 55 | our $VERSION = '0.07053'; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 55 | __PACKAGE__->mk_group_accessors('inherited', qw/ | |||||||||||||||||||||||||||
| 22 | _loader_args | ||||||||||||||||||||||||||||
| 23 | dump_to_dir | ||||||||||||||||||||||||||||
| 24 | _loader_invoked | ||||||||||||||||||||||||||||
| 25 | _loader | ||||||||||||||||||||||||||||
| 26 | loader_class | ||||||||||||||||||||||||||||
| 27 | naming | ||||||||||||||||||||||||||||
| 28 | use_namespaces | ||||||||||||||||||||||||||||
| 29 | /); | ||||||||||||||||||||||||||||
| 30 | 55 | __PACKAGE__->_loader_args({}); | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =head1 NAME | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | DBIx::Class::Schema::Loader - Create a DBIx::Class::Schema based on a database | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | ### use this module to generate a set of class files | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # in a script | ||||||||||||||||||||||||||||
| 43 | use DBIx::Class::Schema::Loader qw/ make_schema_at /; | ||||||||||||||||||||||||||||
| 44 | make_schema_at( | ||||||||||||||||||||||||||||
| 45 | 'My::Schema', | ||||||||||||||||||||||||||||
| 46 | { debug => 1, | ||||||||||||||||||||||||||||
| 47 | dump_directory => './lib', | ||||||||||||||||||||||||||||
| 48 | }, | ||||||||||||||||||||||||||||
| 49 | [ 'dbi:Pg:dbname="foo"', 'myuser', 'mypassword', | ||||||||||||||||||||||||||||
| 50 | { loader_class => 'MyLoader' } # optionally | ||||||||||||||||||||||||||||
| 51 | ], | ||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # from the command line or a shell script with dbicdump (distributed | ||||||||||||||||||||||||||||
| 55 | # with this module). Do `perldoc dbicdump` for usage. | ||||||||||||||||||||||||||||
| 56 | dbicdump -o dump_directory=./lib \ | ||||||||||||||||||||||||||||
| 57 | -o components='["InflateColumn::DateTime"]' \ | ||||||||||||||||||||||||||||
| 58 | -o debug=1 \ | ||||||||||||||||||||||||||||
| 59 | My::Schema \ | ||||||||||||||||||||||||||||
| 60 | 'dbi:Pg:dbname=foo' \ | ||||||||||||||||||||||||||||
| 61 | myuser \ | ||||||||||||||||||||||||||||
| 62 | mypassword | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | ### or generate and load classes at runtime | ||||||||||||||||||||||||||||
| 65 | # note: this technique is not recommended | ||||||||||||||||||||||||||||
| 66 | # for use in production code | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | package My::Schema; | ||||||||||||||||||||||||||||
| 69 | use base qw/DBIx::Class::Schema::Loader/; | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | __PACKAGE__->loader_options( | ||||||||||||||||||||||||||||
| 72 | constraint => '^foo.*', | ||||||||||||||||||||||||||||
| 73 | # debug => 1, | ||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | #### in application code elsewhere: | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | use My::Schema; | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | my $schema1 = My::Schema->connect( $dsn, $user, $password, $attrs); | ||||||||||||||||||||||||||||
| 81 | # -or- | ||||||||||||||||||||||||||||
| 82 | my $schema1 = "My::Schema"; $schema1->connection(as above); | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | DBIx::Class::Schema::Loader automates the definition of a | ||||||||||||||||||||||||||||
| 87 | L<DBIx::Class::Schema> by scanning database table definitions and setting up | ||||||||||||||||||||||||||||
| 88 | the columns, primary keys, unique constraints and relationships. | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | See L<dbicdump> for the C<dbicdump> utility. | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | DBIx::Class::Schema::Loader currently supports only the DBI storage type. It | ||||||||||||||||||||||||||||
| 93 | has explicit support for L<DBD::Pg>, L<DBD::mysql>, L<DBD::DB2>, | ||||||||||||||||||||||||||||
| 94 | L<DBD::Firebird>, L<DBD::InterBase>, L<DBD::Informix>, L<DBD::SQLAnywhere>, | ||||||||||||||||||||||||||||
| 95 | L<DBD::SQLite>, L<DBD::Sybase> (for Sybase ASE and MSSSQL), L<DBD::ODBC> (for | ||||||||||||||||||||||||||||
| 96 | MSSQL, MSAccess, Firebird and SQL Anywhere) L<DBD::ADO> (for MSSQL and | ||||||||||||||||||||||||||||
| 97 | MSAccess) and L<DBD::Oracle>. Other DBI drivers may function to a greater or | ||||||||||||||||||||||||||||
| 98 | lesser degree with this loader, depending on how much of the DBI spec they | ||||||||||||||||||||||||||||
| 99 | implement, and how standard their implementation is. | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | Patches to make other DBDs work correctly welcome. | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | See L<DBIx::Class::Schema::Loader::DBI::Writing> for notes on writing | ||||||||||||||||||||||||||||
| 104 | your own vendor-specific subclass for an unsupported DBD driver. | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | This module requires L<DBIx::Class> 0.08127 or later, and obsoletes the older | ||||||||||||||||||||||||||||
| 107 | L<DBIx::Class::Loader>. | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | See L<DBIx::Class::Schema::Loader::Base> for available options. | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =head1 METHODS | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =head2 loader | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | The loader object, as class data on your Schema. For methods available see | ||||||||||||||||||||||||||||
| 116 | L<DBIx::Class::Schema::Loader::Base> and L<DBIx::Class::Schema::Loader::DBI>. | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =cut | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 595 | ▶ | sub loader { | ||||||||||||||||||||||||||
|
Subroutine
loader: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 121 | 595 | my $self = shift; | |||||||||||||||||||||||||||
| 122 | 595 | $self->_loader(@_); | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =head2 loader_class | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =over 4 | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | =item Argument: $loader_class | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =back | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | Set the loader class to be instantiated when L</connection> is called. | ||||||||||||||||||||||||||||
| 134 | If the classname starts with "::", "DBIx::Class::Schema::Loader" is | ||||||||||||||||||||||||||||
| 135 | prepended. Defaults to L<DBIx::Class::Schema/storage_type> (which must | ||||||||||||||||||||||||||||
| 136 | start with "::" when using L<DBIx::Class::Schema::Loader>). | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | This is mostly useful for subclassing existing loaders or in conjunction | ||||||||||||||||||||||||||||
| 139 | with L</dump_to_dir>. | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =head2 loader_options | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =over 4 | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =item Argument: \%loader_options | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =back | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | Example in Synopsis above demonstrates a few common arguments. For | ||||||||||||||||||||||||||||
| 150 | detailed information on all of the arguments, most of which are | ||||||||||||||||||||||||||||
| 151 | only useful in fairly complex scenarios, see the | ||||||||||||||||||||||||||||
| 152 | L<DBIx::Class::Schema::Loader::Base> documentation. | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | If you intend to use C<loader_options>, you must call | ||||||||||||||||||||||||||||
| 155 | C<loader_options> before any connection is made, or embed the | ||||||||||||||||||||||||||||
| 156 | C<loader_options> in the connection information itself as shown | ||||||||||||||||||||||||||||
| 157 | below. Setting C<loader_options> after the connection has | ||||||||||||||||||||||||||||
| 158 | already been made is useless. | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | =cut | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 141 | ▶ | sub loader_options { | ||||||||||||||||||||||||||
|
Subroutine
loader_options: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 163 | 141 | my $self = shift; | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 141 | ▶ | my %args = (ref $_[0] eq 'HASH') ? %{$_[0]} : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 141 | $self->_loader_args(\%args); | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 141 | $self; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 141 | ▶ | sub _invoke_loader { | ||||||||||||||||||||||||||
|
Subroutine
_invoke_loader: called CC=10 SCAR=23.5
| |||||||||||||||||||||||||||||
| 172 | 141 | my $self = shift; | |||||||||||||||||||||||||||
| 173 | 141 | ▶ | my $class = ref $self || $self; | ||||||||||||||||||||||||||
|
Condition66%2/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table66%2/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 141 | my $args = $self->_loader_args; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | # temporarily copy $self's storage to class | ||||||||||||||||||||||||||||
| 178 | 141 | my $class_storage = $class->storage; | |||||||||||||||||||||||||||
| 179 | 141 | ▶ | if (ref $self) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | 106 | $class->storage($self->storage); | |||||||||||||||||||||||||||
| 181 | 106 | $class->storage->set_schema($class); | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 141 | $args->{schema} = $class; | |||||||||||||||||||||||||||
| 185 | 141 | $args->{schema_class} = $class; | |||||||||||||||||||||||||||
| 186 | 141 | ▶ | $args->{dump_directory} ||= $self->dump_to_dir; | ||||||||||||||||||||||||||
|
Condition66%2/3
$args->{"dump_directory"} ||= $self->dump_to_dir
MC/DC50%1/2
$args->{"dump_directory"} ||= $self->dump_to_dir
$args->{"dump_directory"}
$self->dump_to_dir
Truth table66%2/3
A ||= B
A= $args->{"dump_directory"}B= $self->dump_to_dir
| |||||||||||||||||||||||||||||
| 187 | 141 | ▶ | $args->{naming} = $self->naming if $self->naming; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | 141 | ▶ | $args->{use_namespaces} = $self->use_namespaces if defined $self->use_namespaces; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 141 | my $loader_class = $self->loader_class; | |||||||||||||||||||||||||||
| 191 | 141 | ▶ | if ($loader_class) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | 0 | ▶ | $loader_class = "DBIx::Class::Schema::Loader${loader_class}" if $loader_class =~ /^::/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 0 | $args->{loader_class} = $loader_class; | |||||||||||||||||||||||||||
| 194 | }; | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | # XXX this only works for relative storage_type, like ::DBI ... | ||||||||||||||||||||||||||||
| 197 | 141 | ▶ | my $impl = $loader_class || "DBIx::Class::Schema::Loader" . $self->storage_type; | ||||||||||||||||||||||||||
|
Condition50%1/2
$loader_class || 'DBIx::Class::Schema::Loader' . $self->storage_type
MC/DC0%0/1
$loader_class || 'DBIx::Class::Schema::Loader' . $self->storage_type
$loader_class
Truth table50%1/2
A
A= $loader_class
| |||||||||||||||||||||||||||||
| 198 | 141 | ▶ | try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 199 | 141 | $self->ensure_class_loaded($impl) | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | 1 | ▶ | catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 202 | 1 | croak qq/Could not load loader_class "$impl": "$_"/; | |||||||||||||||||||||||||||
| 203 | 141 | }; | |||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 140 | $class->loader($impl->new(%$args)); | |||||||||||||||||||||||||||
| 206 | 140 | $class->loader->load; | |||||||||||||||||||||||||||
| 207 | 133 | $class->_loader_invoked(1); | |||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | # copy to $self | ||||||||||||||||||||||||||||
| 210 | 133 | ▶ | if (ref $self) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | 98 | $self->loader($class->loader); | |||||||||||||||||||||||||||
| 212 | 98 | $self->_loader_invoked(1); | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 98 | $self->_merge_state_from($class); | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | # restore $class's storage | ||||||||||||||||||||||||||||
| 218 | 133 | $class->storage($class_storage); | |||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 133 | return $self; | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | # FIXME This needs to be moved into DBIC at some point, otherwise we are | ||||||||||||||||||||||||||||
| 224 | # maintaining things to do with DBIC guts, which we have no business of | ||||||||||||||||||||||||||||
| 225 | # maintaining. But at the moment it would be just dead code in DBIC, so we'll | ||||||||||||||||||||||||||||
| 226 | # maintain it here. | ||||||||||||||||||||||||||||
| 227 | 98 | ▶ | sub _merge_state_from { | ||||||||||||||||||||||||||
|
Subroutine
_merge_state_from: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||
| 228 | 98 | my ($self, $from) = @_; | |||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 98 | my $orig_class_mappings = $self->class_mappings; | |||||||||||||||||||||||||||
| 231 | 98 | my $orig_source_registrations = $self->source_registrations; | |||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 98 | $self->_copy_state_from($from); | |||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 98 | ▶ | $self->class_mappings(__merge($orig_class_mappings, $self->class_mappings)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | if $orig_class_mappings; | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 98 | ▶ | $self->source_registrations(__merge($orig_source_registrations, $self->source_registrations)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | if $orig_source_registrations; | ||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 55 | my $merger; | |||||||||||||||||||||||||||
| 243 | 196 | ▶ | sub __merge { | ||||||||||||||||||||||||||
|
Subroutine
__merge: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 196 | local $SIG{__WARN__} = sigwarn_silencer(qr/Arguments for _merge_hashes must be hash references/); | |||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 196 | ▶ | ( $merger ||= do { | ||||||||||||||||||||||||||
|
Condition66%2/3
$merger ||= do {
require Hash::Merge;
my $m = "Hash::Merge"->new("LEFT_PRECEDENT");
$m->set_clone_behavior(0);
$m
}
MC/DC0%0/2
$merger ||= do {
require Hash::Merge;
my $m = "Hash::Merge"->new("LEFT_PRECEDENT");
$m->set_clone_behavior(0);
$m
}
$merger
do {
require Hash::Merge;
my $m = "Hash::Merge"->new("LEFT_PRECEDENT");
$m->set_clone_behavior(0);
$m
}
Truth table66%2/3
A ||= B
A= $mergerB= do {
require Hash::Merge;
my $m = "Hash::Merge"->new("LEFT_PRECEDENT");
$m->set_clone_behavior(0);
$m
}
| |||||||||||||||||||||||||||||
| 248 | 45 | require Hash::Merge; | |||||||||||||||||||||||||||
| 249 | 45 | my $m = Hash::Merge->new('LEFT_PRECEDENT'); | |||||||||||||||||||||||||||
| 250 | 45 | $m->set_clone_behavior(0); | |||||||||||||||||||||||||||
| 251 | 45 | $m; | |||||||||||||||||||||||||||
| 252 | } )->merge( | ||||||||||||||||||||||||||||
| 253 | $_[0], $_[1] | ||||||||||||||||||||||||||||
| 254 | ); | ||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 287 | ▶ | sub _copy_state_from { | ||||||||||||||||||||||||||
|
Subroutine
_copy_state_from: called CC=4 SCAR=21.7
| |||||||||||||||||||||||||||||
| 258 | 287 | my $self = shift; | |||||||||||||||||||||||||||
| 259 | 287 | my ($from) = @_; | |||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | # older DBIC's do not have this method | ||||||||||||||||||||||||||||
| 262 | 287 | ▶ | if (try { DBIx::Class->VERSION('0.08197'); 1 }) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | 287 | return $self->next::method(@_); | |||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | else { | ||||||||||||||||||||||||||||
| 266 | # this is a copy from DBIC git master pre 0.08197 | ||||||||||||||||||||||||||||
| 267 | 0 | $self->class_mappings({ %{$from->class_mappings} }); | |||||||||||||||||||||||||||
| 268 | 0 | $self->source_registrations({ %{$from->source_registrations} }); | |||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 0 | foreach my $moniker ($from->sources) { | |||||||||||||||||||||||||||
| 271 | 0 | my $source = $from->source($moniker); | |||||||||||||||||||||||||||
| 272 | 0 | my $new = $source->new($source); | |||||||||||||||||||||||||||
| 273 | # we use extra here as we want to leave the class_mappings as they are | ||||||||||||||||||||||||||||
| 274 | # but overwrite the source_registrations entry with the new source | ||||||||||||||||||||||||||||
| 275 | 0 | $self->register_extra_source($moniker => $new); | |||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 0 | ▶ | if ($from->storage) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 279 | 0 | $self->storage($from->storage); | |||||||||||||||||||||||||||
| 280 | 0 | $self->storage->set_schema($self); | |||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | =head2 connection | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | =over 4 | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | =item Arguments: @args | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | =item Return Value: $new_schema | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | =back | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | See L<DBIx::Class::Schema/connection> for basic usage. | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | If the final argument is a hashref, and it contains the keys C<loader_options> | ||||||||||||||||||||||||||||
| 298 | or C<loader_class>, those keys will be deleted, and their values value will be | ||||||||||||||||||||||||||||
| 299 | used for the loader options or class, respectively, just as if set via the | ||||||||||||||||||||||||||||
| 300 | L</loader_options> or L</loader_class> methods above. | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | The actual auto-loading operation (the heart of this module) will be invoked | ||||||||||||||||||||||||||||
| 303 | as soon as the connection information is defined. | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | =cut | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | 144 | ▶ | sub connection { | ||||||||||||||||||||||||||
|
Subroutine
connection: called CC=17 SCAR=28.4
Pod
documented
| |||||||||||||||||||||||||||||
| 308 | 144 | my $self = shift; | |||||||||||||||||||||||||||
| 309 | 144 | ▶ | my $class = ref $self || $self; | ||||||||||||||||||||||||||
|
Condition66%2/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table66%2/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | 144 | ▶ | if($_[-1] && ref $_[-1] eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$_[-1] and ref $_[-1] eq "HASH"
MC/DC100%2/2
$_[-1] and ref $_[-1] eq "HASH"
$_[-1]
ref $_[-1] eq "HASH"
Truth table100%3/3
A and B
A= $_[-1]B= ref $_[-1] eq "HASH"
| |||||||||||||||||||||||||||||
| 312 | 7 | for my $option (qw/loader_class loader_options/) { | |||||||||||||||||||||||||||
| 313 | 14 | ▶ | if(my $value = delete $_[-1]->{$option}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 314 | 3 | $self->$option($value); | |||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||
| 317 | 7 | ▶ | pop @_ if !keys %{$_[-1]}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | # Make sure we inherit from schema_base_class and load schema_components | ||||||||||||||||||||||||||||
| 321 | # before connecting. | ||||||||||||||||||||||||||||
| 322 | 144 | require DBIx::Class::Schema::Loader::Base; | |||||||||||||||||||||||||||
| 323 | my $temp_loader = DBIx::Class::Schema::Loader::Base->new( | ||||||||||||||||||||||||||||
| 324 | 144 | %{ $self->_loader_args }, | |||||||||||||||||||||||||||
| 325 | schema => $self, | ||||||||||||||||||||||||||||
| 326 | naming => 'current', | ||||||||||||||||||||||||||||
| 327 | use_namespaces => 1, | ||||||||||||||||||||||||||||
| 328 | ); | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | 142 | my $modify_isa = 0; | |||||||||||||||||||||||||||
| 331 | 142 | my @components; | |||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 142 | ▶ | if ($temp_loader->schema_base_class || $temp_loader->schema_components) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$temp_loader->schema_base_class or $temp_loader->schema_components
MC/DC0%0/2
$temp_loader->schema_base_class or $temp_loader->schema_components
$temp_loader->schema_base_class
$temp_loader->schema_components
Truth table66%2/3
A or B
A= $temp_loader->schema_base_classB= $temp_loader->schema_components
| |||||||||||||||||||||||||||||
| 334 | 142 | ▶ | @components = @{ $temp_loader->schema_components } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 335 | if $temp_loader->schema_components; | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | 142 | ▶ | push @components, ('+'.$temp_loader->schema_base_class) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 338 | if $temp_loader->schema_base_class; | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 142 | my $class_isa = do { | |||||||||||||||||||||||||||
| 341 | 55 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 342 | 142 | \@{"${class}::ISA"}; | |||||||||||||||||||||||||||
| 343 | }; | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | my @component_classes = map { | ||||||||||||||||||||||||||||
| 346 | 142 | ▶ | /^\+/ ? substr($_, 1, length($_) - 1) : "DBIx::Class::$_" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 347 | } @components; | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | 142 | ▶ | $modify_isa++ if not array_eq([ @$class_isa[0..(@components-1)] ], \@component_classes) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 142 | ▶ | if ($modify_isa) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 353 | 8 | $class->load_components(@components); | |||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | # This hack is necessary because we changed @ISA of $self through | ||||||||||||||||||||||||||||
| 356 | # ->load_components and we are now in a different place in the mro. | ||||||||||||||||||||||||||||
| 357 | 55 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 8 | ▶ | local *connection = set_subname __PACKAGE__.'::connection' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 360 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 361 | 8 | $self->next::method(@_); | |||||||||||||||||||||||||||
| 362 | 8 | }; | |||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | 8 | my @linear_isa = @{ mro::get_linear_isa($class) }; | |||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | 8 | my $next_method; | |||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | 8 | foreach my $i (1..$#linear_isa) { | |||||||||||||||||||||||||||
| 369 | 55 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 370 | 10 | $next_method = *{$linear_isa[$i].'::connection'}{CODE}; | |||||||||||||||||||||||||||
| 371 | 10 | ▶ | last if $next_method; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | 8 | $self = $self->$next_method(@_); | |||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||
| 376 | else { | ||||||||||||||||||||||||||||
| 377 | 134 | $self = $self->next::method(@_); | |||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | 142 | ▶ | if(!$class->_loader_invoked) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 381 | 141 | $self->_invoke_loader | |||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | 134 | return $self; | |||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | =head2 clone | ||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | See L<DBIx::Class::Schema/clone>. | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | =cut | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | 189 | ▶ | sub clone { | ||||||||||||||||||||||||||
|
Subroutine
clone: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 394 | 189 | my $self = shift; | |||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | 189 | my $clone = $self->next::method(@_); | |||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | 189 | ▶ | if($clone->_loader_args) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 399 | 189 | $clone->_loader_args->{schema} = $clone; | |||||||||||||||||||||||||||
| 400 | 189 | weaken($clone->_loader_args->{schema}); | |||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | 189 | $clone; | |||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | =head2 dump_to_dir | ||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | =over 4 | ||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | =item Argument: $directory | ||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | =back | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | Calling this as a class method on either L<DBIx::Class::Schema::Loader> | ||||||||||||||||||||||||||||
| 415 | or any derived schema class will cause all schemas to dump | ||||||||||||||||||||||||||||
| 416 | manual versions of themselves to the named directory when they are | ||||||||||||||||||||||||||||
| 417 | loaded. In order to be effective, this must be set before defining a | ||||||||||||||||||||||||||||
| 418 | connection on this schema class or any derived object (as the loading | ||||||||||||||||||||||||||||
| 419 | happens as soon as both a connection and loader_options are set, and | ||||||||||||||||||||||||||||
| 420 | only once per class). | ||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | See L<DBIx::Class::Schema::Loader::Base/dump_directory> for more | ||||||||||||||||||||||||||||
| 423 | details on the dumping mechanism. | ||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | This can also be set at module import time via the import option | ||||||||||||||||||||||||||||
| 426 | C<dump_to_dir:/foo/bar> to L<DBIx::Class::Schema::Loader>, where | ||||||||||||||||||||||||||||
| 427 | C</foo/bar> is the target directory. | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | Examples: | ||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | # My::Schema isa DBIx::Class::Schema::Loader, and has connection info | ||||||||||||||||||||||||||||
| 432 | # hardcoded in the class itself: | ||||||||||||||||||||||||||||
| 433 | perl -MDBIx::Class::Schema::Loader=dump_to_dir:/foo/bar -MMy::Schema -e1 | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | # Same, but no hard-coded connection, so we must provide one: | ||||||||||||||||||||||||||||
| 436 | perl -MDBIx::Class::Schema::Loader=dump_to_dir:/foo/bar -MMy::Schema -e 'My::Schema->connection("dbi:Pg:dbname=foo", ...)' | ||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | # Or as a class method, as long as you get it done *before* defining a | ||||||||||||||||||||||||||||
| 439 | # connection on this schema class or any derived object: | ||||||||||||||||||||||||||||
| 440 | use My::Schema; | ||||||||||||||||||||||||||||
| 441 | My::Schema->dump_to_dir('/foo/bar'); | ||||||||||||||||||||||||||||
| 442 | My::Schema->connection(........); | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | # Or as a class method on the DBIx::Class::Schema::Loader itself, which affects all | ||||||||||||||||||||||||||||
| 445 | # derived schemas | ||||||||||||||||||||||||||||
| 446 | use My::Schema; | ||||||||||||||||||||||||||||
| 447 | use My::OtherSchema; | ||||||||||||||||||||||||||||
| 448 | DBIx::Class::Schema::Loader->dump_to_dir('/foo/bar'); | ||||||||||||||||||||||||||||
| 449 | My::Schema->connection(.......); | ||||||||||||||||||||||||||||
| 450 | My::OtherSchema->connection(.......); | ||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | # Another alternative to the above: | ||||||||||||||||||||||||||||
| 453 | use DBIx::Class::Schema::Loader qw| dump_to_dir:/foo/bar |; | ||||||||||||||||||||||||||||
| 454 | use My::Schema; | ||||||||||||||||||||||||||||
| 455 | use My::OtherSchema; | ||||||||||||||||||||||||||||
| 456 | My::Schema->connection(.......); | ||||||||||||||||||||||||||||
| 457 | My::OtherSchema->connection(.......); | ||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | =cut | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | 54 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=7 SCAR=22.2
| |||||||||||||||||||||||||||||
| 462 | 54 | my $self = shift; | |||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | 54 | ▶ | return if !@_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | 39 | my $cpkg = (caller)[0]; | |||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | 39 | foreach my $opt (@_) { | |||||||||||||||||||||||||||
| 469 | 39 | ▶ | if($opt =~ m{^dump_to_dir:(.*)$}) { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 470 | 0 | $self->dump_to_dir($1) | |||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||
| 472 | elsif($opt eq 'make_schema_at') { | ||||||||||||||||||||||||||||
| 473 | 55 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 474 | 39 | *{"${cpkg}::make_schema_at"} = \&make_schema_at; | |||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||
| 476 | elsif($opt eq 'naming') { | ||||||||||||||||||||||||||||
| 477 | 55 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 478 | 0 | *{"${cpkg}::naming"} = $self->curry::naming; | |||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||
| 480 | elsif($opt eq 'use_namespaces') { | ||||||||||||||||||||||||||||
| 481 | 55 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 482 | 0 | *{"${cpkg}::use_namespaces"} = $self->curry::use_namespaces, | |||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | =head2 make_schema_at | ||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | =over 4 | ||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | =item Arguments: $schema_class_name, \%loader_options, \@connect_info | ||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | =item Return Value: $schema_class_name | ||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||
| 495 | =back | ||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | This function creates a DBIx::Class schema from an existing RDBMS | ||||||||||||||||||||||||||||
| 498 | schema. With the C<dump_directory> option, generates a set of | ||||||||||||||||||||||||||||
| 499 | DBIx::Class classes from an existing database schema read from the | ||||||||||||||||||||||||||||
| 500 | given dsn. Without a C<dump_directory>, creates schema classes in | ||||||||||||||||||||||||||||
| 501 | memory at runtime without generating on-disk class files. | ||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | For a complete list of supported loader_options, see | ||||||||||||||||||||||||||||
| 504 | L<DBIx::Class::Schema::Loader::Base> | ||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | The last hashref in the C<\@connect_info> can specify the L</loader_class>. | ||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | This function can be imported in the usual way, as illustrated in | ||||||||||||||||||||||||||||
| 509 | these Examples: | ||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | # Simple example, creates as a new class 'New::Schema::Name' in | ||||||||||||||||||||||||||||
| 512 | # memory in the running perl interpreter. | ||||||||||||||||||||||||||||
| 513 | use DBIx::Class::Schema::Loader qw/ make_schema_at /; | ||||||||||||||||||||||||||||
| 514 | make_schema_at( | ||||||||||||||||||||||||||||
| 515 | 'New::Schema::Name', | ||||||||||||||||||||||||||||
| 516 | { debug => 1 }, | ||||||||||||||||||||||||||||
| 517 | [ 'dbi:Pg:dbname="foo"','postgres','', | ||||||||||||||||||||||||||||
| 518 | { loader_class => 'MyLoader' } # optionally | ||||||||||||||||||||||||||||
| 519 | ], | ||||||||||||||||||||||||||||
| 520 | ); | ||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||
| 522 | # Inside a script, specifying a dump directory in which to write | ||||||||||||||||||||||||||||
| 523 | # class files | ||||||||||||||||||||||||||||
| 524 | use DBIx::Class::Schema::Loader qw/ make_schema_at /; | ||||||||||||||||||||||||||||
| 525 | make_schema_at( | ||||||||||||||||||||||||||||
| 526 | 'New::Schema::Name', | ||||||||||||||||||||||||||||
| 527 | { debug => 1, dump_directory => './lib' }, | ||||||||||||||||||||||||||||
| 528 | [ 'dbi:Pg:dbname="foo"','postgres','', | ||||||||||||||||||||||||||||
| 529 | { loader_class => 'MyLoader' } # optionally | ||||||||||||||||||||||||||||
| 530 | ], | ||||||||||||||||||||||||||||
| 531 | ); | ||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||
| 533 | The last hashref in the C<\@connect_info> is checked for loader arguments such | ||||||||||||||||||||||||||||
| 534 | as C<loader_options> and C<loader_class>, see L</connection> for more details. | ||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | =cut | ||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||
| 538 | 62 | ▶ | sub make_schema_at { | ||||||||||||||||||||||||||
|
Subroutine
make_schema_at: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 539 | 62 | my ($target, $opts, $connect_info) = @_; | |||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | { | ||||||||||||||||||||||||||||
| 542 | 55 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 543 | 62 | @{$target . '::ISA'} = qw/DBIx::Class::Schema::Loader/; | |||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | 62 | $target->_loader_invoked(0); | |||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||
| 548 | 62 | $target->loader_options($opts); | |||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||
| 550 | 62 | my $temp_schema = $target->connect(@$connect_info); | |||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | 55 | $target->storage($temp_schema->storage); | |||||||||||||||||||||||||||
| 553 | 55 | $target->storage->set_schema($target); | |||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | 55 | return $target; | |||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||
| 558 | =head2 rescan | ||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||
| 560 | =over 4 | ||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | =item Return Value: @new_monikers | ||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | =back | ||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||
| 566 | Re-scans the database for newly added tables since the initial | ||||||||||||||||||||||||||||
| 567 | load, and adds them to the schema at runtime, including relationships, | ||||||||||||||||||||||||||||
| 568 | etc. Does not process drops or changes. | ||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | Returns a list of the new monikers added. | ||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||
| 572 | =cut | ||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||
| 574 | 5 | ▶ | sub rescan { my $self = shift; $self->loader->rescan($self) } | ||||||||||||||||||||||||||
|
Subroutine
rescan: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||
| 576 | =head2 naming | ||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||
| 578 | =over 4 | ||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||
| 580 | =item Arguments: \%opts | $ver | ||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||
| 582 | =back | ||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||
| 584 | Controls the naming options for backward compatibility, see | ||||||||||||||||||||||||||||
| 585 | L<DBIx::Class::Schema::Loader::Base/naming> for details. | ||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||
| 587 | To upgrade a dynamic schema, use: | ||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||
| 589 | __PACKAGE__->naming('current'); | ||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||
| 591 | Can be imported into your dump script and called as a function as well: | ||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||
| 593 | naming('v4'); | ||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||
| 595 | =head2 use_namespaces | ||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||
| 597 | =over 4 | ||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||
| 599 | =item Arguments: 1|0 | ||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||
| 601 | =back | ||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||
| 603 | Controls the use_namespaces options for backward compatibility, see | ||||||||||||||||||||||||||||
| 604 | L<DBIx::Class::Schema::Loader::Base/use_namespaces> for details. | ||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||
| 606 | To upgrade a dynamic schema, use: | ||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||
| 608 | __PACKAGE__->use_namespaces(1); | ||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||
| 610 | Can be imported into your dump script and called as a function as well: | ||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||
| 612 | use_namespaces(1); | ||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||
| 614 | =head1 KNOWN ISSUES | ||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||
| 616 | =head2 Multiple Database Schemas | ||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||
| 618 | See L<DBIx::Class::Schema::Loader::Base/db_schema>. | ||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||
| 620 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||
| 622 | Matt S Trout, all of the #dbix-class folks, and everyone who's ever sent | ||||||||||||||||||||||||||||
| 623 | in a bug report or suggestion. | ||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||
| 625 | Based on L<DBIx::Class::Loader> by Sebastian Riedel | ||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||
| 627 | Based upon the work of IKEBE Tomohiro | ||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||
| 629 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||
| 631 | Caelum: Rafael Kitover <rkitover@cpan.org> | ||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||
| 633 | Dag-Erling Smørgrav <des@des.no> | ||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||
| 635 | Matias E. Fernandez <mfernandez@pisco.ch> | ||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||
| 637 | SineSwiper: Brendan Byrd <byrd.b@insightcom.com> | ||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||
| 639 | TSUNODA Kazuya <drk@drk7.jp> | ||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||
| 641 | acmoore: Andrew Moore <amoore@cpan.org> | ||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||
| 643 | alnewkirk: Al Newkirk <awncorp@cpan.org> | ||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||
| 645 | andrewalker: André Walker <andre@andrewalker.net> | ||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||
| 647 | angelixd: Paul C. Mantz <pcmantz@cpan.org> | ||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||
| 649 | arc: Aaron Crane <arc@cpan.org> | ||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||
| 651 | arcanez: Justin Hunter <justin.d.hunter@gmail.com> | ||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||
| 653 | ash: Ash Berlin <ash@cpan.org> | ||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||
| 655 | blblack: Brandon Black <blblack@gmail.com> | ||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||
| 657 | bphillips: Brian Phillips <bphillips@cpan.org> | ||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||
| 659 | btilly: Ben Tilly <btilly@gmail.com> | ||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||
| 661 | domm: Thomas Klausner <domm@plix.at> | ||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||
| 663 | ether: Karen Etheridge <ether@cpan.org> | ||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||
| 665 | gugu: Andrey Kostenko <a.kostenko@rambler-co.ru> | ||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||
| 667 | hobbs: Andrew Rodland <arodland@cpan.org> | ||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||
| 669 | ilmari: Dagfinn Ilmari MannsE<aring>ker <ilmari@ilmari.org> | ||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||
| 671 | jhannah: Jay Hannah <jay@jays.net> | ||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||
| 673 | jnap: John Napiorkowski <jjn1056@yahoo.com> | ||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||
| 675 | kane: Jos Boumans <kane@cpan.org> | ||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||
| 677 | mattp: Matt Phillips <mattp@cpan.org> | ||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||
| 679 | mephinet: Philipp Gortan <philipp.gortan@apa.at> | ||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||
| 681 | moritz: Moritz Lenz <moritz@faui2k3.org> | ||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||
| 683 | mst: Matt S. Trout <mst@shadowcatsystems.co.uk> | ||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||
| 685 | mstratman: Mark A. Stratman <stratman@gmail.com> | ||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||
| 687 | oalders: Olaf Alders <olaf@wundersolutions.com> | ||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||
| 689 | rbo: Robert Bohne <rbo@cpan.org> | ||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||
| 691 | rbuels: Robert Buels <rbuels@gmail.com> | ||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||
| 693 | ribasushi: Peter Rabbitson <ribasushi@cpan.org> | ||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||
| 695 | schwern: Michael G. Schwern <mschwern@cpan.org> | ||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||
| 697 | spb: Stephen Bennett <spb@exherbo.org> | ||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||
| 699 | timbunce: Tim Bunce <timb@cpan.org> | ||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||
| 701 | waawaamilk: Nigel McNie <nigel@mcnie.name> | ||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||
| 703 | ... and lots of other folks. If we forgot you, please write the current | ||||||||||||||||||||||||||||
| 704 | maintainer or RT. | ||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||
| 706 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||
| 708 | Copyright (c) 2006 - 2015 by the aforementioned | ||||||||||||||||||||||||||||
| 709 | L<DBIx::Class::Schema::Loader/AUTHORS>. | ||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||
| 711 | This library is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 712 | the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||
| 714 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||
| 716 | L<DBIx::Class>, L<DBIx::Class::Manual::Intro>, L<DBIx::Class::Tutorial>, | ||||||||||||||||||||||||||||
| 717 | L<DBIx::Class::Schema::Loader::Base> | ||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||
| 719 | =cut | ||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||
| 721 | 55 | 1; | |||||||||||||||||||||||||||
| 722 | # vim:et sts=4 sw=4 tw=0: | ||||||||||||||||||||||||||||