use Carp::Clan qw/^DBIx::Class|^Try::Tiny/;
use Scalar::Util qw/blessed/;
use Try::Tiny;
+use namespace::clean;
use overload
'""' => sub { shift->{msg} },
use base qw/DBIx::Class/;
use Carp::Clan qw/^DBIx::Class/;
use Try::Tiny;
+use namespace::clean;
=head1 NAME
=head1 SYNOPSIS
-Load this component and then declare one or more
+Load this component and then declare one or more
columns to be of the datetime, timestamp or date datatype.
package Event;
=head1 DESCRIPTION
-This module figures out the type of DateTime::Format::* class to
-inflate/deflate with based on the type of DBIx::Class::Storage::DBI::*
-that you are using. If you switch from one database to a different
+This module figures out the type of DateTime::Format::* class to
+inflate/deflate with based on the type of DBIx::Class::Storage::DBI::*
+that you are using. If you switch from one database to a different
one your code should continue to work without modification (though note
that this feature is new as of 0.07, so it may not be perfect yet - bug
reports to the list very much welcome).
=over 4
-=item More information about the add_columns method, and column metadata,
+=item More information about the add_columns method, and column metadata,
can be found in the documentation for L<DBIx::Class::ResultSource>.
=item Further discussion of problems inherent to the Floating timezone:
- L<Floating DateTimes|DateTime/Floating_DateTimes>
+ L<Floating DateTimes|DateTime/Floating_DateTimes>
and L<< $dt->set_time_zone|DateTime/"Set" Methods >>
=back
use Scalar::Util ();
use base qw/DBIx::Class/;
use Try::Tiny;
+use namespace::clean;
=head1 NAME
=item is_foreign_key_constraint
If you are using L<SQL::Translator> to create SQL for you and you find that it
-is creating constraints where it shouldn't, or not creating them where it
+is creating constraints where it shouldn't, or not creating them where it
should, set this attribute to a true or false value to override the detection
of when to create constraints.
If C<cascade_copy> is true on a C<has_many> relationship for an
object, then when you copy the object all the related objects will
-be copied too. To turn this behaviour off, pass C<< cascade_copy => 0 >>
-in the C<$attr> hashref.
+be copied too. To turn this behaviour off, pass C<< cascade_copy => 0 >>
+in the C<$attr> hashref.
The behaviour defaults to C<< cascade_copy => 1 >> for C<has_many>
relationships.
By default, DBIx::Class cascades deletes across C<has_many>,
C<has_one> and C<might_have> relationships. You can disable this
-behaviour on a per-relationship basis by supplying
+behaviour on a per-relationship basis by supplying
C<< cascade_delete => 0 >> in the relationship attributes.
The cascaded operations are performed after the requested delete,
=item on_delete / on_update
If you are using L<SQL::Translator> to create SQL for you, you can use these
-attributes to explicitly set the desired C<ON DELETE> or C<ON UPDATE> constraint
-type. If not supplied the SQLT parser will attempt to infer the constraint type by
+attributes to explicitly set the desired C<ON DELETE> or C<ON UPDATE> constraint
+type. If not supplied the SQLT parser will attempt to infer the constraint type by
interrogating the attributes of the B<opposite> relationship. For any 'multi'
-relationship with C<< cascade_delete => 1 >>, the corresponding belongs_to
-relationship will be created with an C<ON DELETE CASCADE> constraint. For any
+relationship with C<< cascade_delete => 1 >>, the corresponding belongs_to
+relationship will be created with an C<ON DELETE CASCADE> constraint. For any
relationship bearing C<< cascade_copy => 1 >> the resulting belongs_to constraint
will be C<ON UPDATE CASCADE>. If you wish to disable this autodetection, and just
-use the RDBMS' default constraint type, pass C<< on_delete => undef >> or
+use the RDBMS' default constraint type, pass C<< on_delete => undef >> or
C<< on_delete => '' >>, and the same for C<on_update> respectively.
=item is_deferrable
( $objects_rs ) = $rs->search_related_rs('relname', $cond, $attrs);
-This method works exactly the same as search_related, except that
+This method works exactly the same as search_related, except that
it guarantees a resultset, even in list context.
=cut
my $new_obj = $obj->new_related('relname', \%col_data);
Create a new item of the related foreign class. If called on a
-L<Row|DBIx::Class::Manual::Glossary/"Row"> object, it will magically
-set any foreign key columns of the new object to the related primary
-key columns of the source object for you. The newly created item will
+L<Row|DBIx::Class::Manual::Glossary/"Row"> object, it will magically
+set any foreign key columns of the new object to the related primary
+key columns of the source object for you. The newly created item will
not be saved into your storage until you call L<DBIx::Class::Row/insert>
on it.
=back
my $actor = $schema->resultset('Actor')->find(1);
- my @roles = $schema->resultset('Role')->search({ role =>
+ my @roles = $schema->resultset('Role')->search({ role =>
{ '-in' => ['Fred', 'Barney'] } } );
$actor->set_roles(\@roles);
use strict;
use warnings;
use Try::Tiny;
+use namespace::clean;
-our %_pod_inherit_config =
+our %_pod_inherit_config =
(
class_map => { 'DBIx::Class::Relationship::BelongsTo' => 'DBIx::Class::Relationship' }
);
my ($class, $rel, $f_class, $cond, $attrs) = @_;
# assume a foreign key contraint unless defined otherwise
- $attrs->{is_foreign_key_constraint} = 1
+ $attrs->{is_foreign_key_constraint} = 1
if not exists $attrs->{is_foreign_key_constraint};
$attrs->{undef_on_null_fk} = 1
if not exists $attrs->{undef_on_null_fk};
use strict;
use warnings;
use Try::Tiny;
+use namespace::clean;
-our %_pod_inherit_config =
+our %_pod_inherit_config =
(
class_map => { 'DBIx::Class::Relationship::HasMany' => 'DBIx::Class::Relationship' }
);
unless (ref $cond) {
$class->ensure_class_loaded($f_class);
- my ($pri, $too_many) = try { $class->_pri_cols }
+ my ($pri, $too_many) = try { $class->_pri_cols }
catch {
$class->throw_exception("Can't infer join condition for ${rel} on ${class}: $_");
};
use warnings;
use Carp::Clan qw/^DBIx::Class/;
use Try::Tiny;
+use namespace::clean;
-our %_pod_inherit_config =
+our %_pod_inherit_config =
(
class_map => { 'DBIx::Class::Relationship::HasOne' => 'DBIx::Class::Relationship' }
);
use DBIx::Class::Exception;
use Carp::Clan qw/^DBIx::Class/;
use Try::Tiny;
+use namespace::clean;
use base qw/DBIx::Class/;
If a column name beginning with a plus sign ('+col1') is provided, the
attributes provided will be merged with any existing attributes for the
column, with the new attributes taking precedence in the case that an
-attribute already exists. Using this without a hashref
+attribute already exists. Using this without a hashref
(C<< $source->add_columns(qw/+col1 +col2/) >>) is legal, but useless --
it does the same thing it would do without the plus.
This contains the column type. It is automatically filled if you use the
L<SQL::Translator::Producer::DBIx::Class::File> producer, or the
-L<DBIx::Class::Schema::Loader> module.
+L<DBIx::Class::Schema::Loader> module.
Currently there is no standard set of values for the data_type. Use
whatever your database supports.
my $schema = $source->schema();
-Returns the L<DBIx::Class::Schema> object that this result source
+Returns the L<DBIx::Class::Schema> object that this result source
belongs to.
=head2 storage
keys %{$rel_info->{cond}};
my @ord = (ref($rel_info->{attrs}{order_by}) eq 'ARRAY'
? @{$rel_info->{attrs}{order_by}}
-
+
: (defined $rel_info->{attrs}{order_by}
? ($rel_info->{attrs}{order_by})
: ()));
=head2 handle
-Obtain a new handle to this source. Returns an instance of a
+Obtain a new handle to this source. Returns an instance of a
L<DBIx::Class::ResultSourceHandle>.
=cut
use DBIx::Class::Exception;
use Scalar::Util ();
use Try::Tiny;
+use namespace::clean;
###
### Internal method
if ($source->isa('DBIx::Class::ResultSourceHandle')) {
$source = $source_handle->resolve
- }
+ }
else {
$source_handle = $source->handle
}
use File::Spec;
use Sub::Name ();
use Module::Find();
+use namespace::clean;
use base qw/DBIx::Class/;
If a Result class is found to already have a ResultSet class set using
L</resultset_class> to some other class, you will be warned like this:
- We found ResultSet class '$rs_class' for '$result', but it seems
+ We found ResultSet class '$rs_class' for '$result', but it seems
that you had already set '$result' to use '$rs_set' instead
Both of the sub-namespaces are configurable if you don't like the defaults,
If any classes found do not appear to be Result class files, you will
get the following warning:
- Failed to load $comp_class. Can't find source_name method. Is
+ Failed to load $comp_class. Can't find source_name method. Is
$comp_class really a full DBIC result class? Fix it, move it elsewhere,
or make your load_classes call more specific.
=back
-An optional sub which you can declare in your own Schema class that will get
+An optional sub which you can declare in your own Schema class that will get
passed the L<SQL::Translator::Schema> object when you deploy the schema via
L</create_ddl_dir> or L</deploy>.
-For an example of what you can do with this, see
+For an example of what you can do with this, see
L<DBIx::Class::Manual::Cookbook/Adding Indexes And Functions To Your SQL>.
Note that sqlt_deploy_hook is called by L</deployment_statements>, which in turn
=head2 txn_scope_guard
-Runs C<txn_scope_guard> on the schema's storage. See
+Runs C<txn_scope_guard> on the schema's storage. See
L<DBIx::Class::Storage/txn_scope_guard>.
=cut
Pass this method a resultsource name, and an arrayref of
arrayrefs. The arrayrefs should contain a list of column names,
-followed by one or many sets of matching data for the given columns.
+followed by one or many sets of matching data for the given columns.
In void context, C<insert_bulk> in L<DBIx::Class::Storage::DBI> is used
to insert the data, as this is a fast method. However, insert_bulk currently
...
]);
-Since wantarray context is basically the same as looping over $rs->create(...)
+Since wantarray context is basically the same as looping over $rs->create(...)
you won't see any performance benefits and in this case the method is more for
convenience. Void context sends the column information directly to storage
-using <DBI>s bulk insert method. So the performance will be much better for
+using <DBI>s bulk insert method. So the performance will be much better for
storages that support this method.
-Because of this difference in the way void context inserts rows into your
+Because of this difference in the way void context inserts rows into your
database you need to note how this will effect any loaded components that
-override or augment insert. For example if you are using a component such
-as L<DBIx::Class::UUIDColumns> to populate your primary keys you MUST use
+override or augment insert. For example if you are using a component such
+as L<DBIx::Class::UUIDColumns> to populate your primary keys you MUST use
wantarray context if you want the PKs automatically created.
=cut
$rs->populate($data);
}
} else {
- $self->throw_exception("$name is not a resultset");
+ $self->throw_exception("$name is not a resultset");
}
}
my ($self, @info) = @_;
return $self if !@info && $self->storage;
- my ($storage_class, $args) = ref $self->storage_type ?
+ my ($storage_class, $args) = ref $self->storage_type ?
($self->_normalize_storage_type($self->storage_type),{}) : ($self->storage_type, {});
$storage_class = 'DBIx::Class::Storage'.$storage_class
=head2 svp_begin
-Creates a new savepoint (does nothing outside a transaction).
+Creates a new savepoint (does nothing outside a transaction).
Equivalent to calling $schema->storage->svp_begin. See
L<DBIx::Class::Storage/"svp_begin"> for more information.
=head2 svp_release
-Releases a savepoint (does nothing outside a transaction).
+Releases a savepoint (does nothing outside a transaction).
Equivalent to calling $schema->storage->svp_release. See
L<DBIx::Class::Storage/"svp_release"> for more information.
=head2 svp_rollback
-Rollback to a savepoint (does nothing outside a transaction).
+Rollback to a savepoint (does nothing outside a transaction).
Equivalent to calling $schema->storage->svp_rollback. See
L<DBIx::Class::Storage/"svp_rollback"> for more information.
created. For quoting purposes supply C<quote_table_names> and
C<quote_field_names>.
-Additionally, the DBIx::Class parser accepts a C<sources> parameter as a hash
-ref or an array ref, containing a list of source to deploy. If present, then
+Additionally, the DBIx::Class parser accepts a C<sources> parameter as a hash
+ref or an array ref, containing a list of source to deploy. If present, then
only the sources listed will get deployed. Furthermore, you can use the
C<add_fk_index> parser parameter to prevent the parser from creating an index for each
FK.
=back
-A convenient shortcut to
+A convenient shortcut to
C<< $self->storage->create_ddl_dir($self, @args) >>.
Creates an SQL file based on the Schema, for each of the specified
my $filename = $table->ddl_filename($type, $dir, $version, $preversion)
In recent versions variables $dir and $version were reversed in order to
- bring the signature in line with other Schema/Storage methods. If you
+ bring the signature in line with other Schema/Storage methods. If you
really need to maintain backward compatibility, you can do the following
in any overriding methods:
=head2 thaw
-Provided as the recommended way of thawing schema objects. You can call
+Provided as the recommended way of thawing schema objects. You can call
C<Storable::thaw> directly if you wish, but the thawed objects will not have a
reference to any schema, so are rather useless.
=back
-This method is called by L</load_namespaces> and L</load_classes> to install the found classes into your Schema. You should be using those instead of this one.
+This method is called by L</load_namespaces> and L</load_classes> to install the found classes into your Schema. You should be using those instead of this one.
You will only need this method if you have your Result classes in
files which are not named after the packages (or all in the same
=back
-As L</register_source> but should be used if the result class already
+As L</register_source> but should be used if the result class already
has a source and you want to register an extra one.
=cut
sub _unregister_source {
my ($self, $moniker) = @_;
- my %reg = %{$self->source_registrations};
+ my %reg = %{$self->source_registrations};
my $source = delete $reg{$moniker};
$self->source_registrations(\%reg);
use Carp::Clan qw/^DBIx::Class/;
use Time::HiRes qw/gettimeofday/;
use Try::Tiny;
+use namespace::clean;
__PACKAGE__->mk_classdata('_filedata');
__PACKAGE__->mk_classdata('upgrade_directory');
# This is necessary since there are legitimate cases when upgrades can happen
# back to back within the same second. This breaks things since we relay on the
# ability to sort by the 'installed' value. The logical choice of an autoinc
- # is not possible, as it will break multiple legacy installations. Also it is
+ # is not possible, as it will break multiple legacy installations. Also it is
# not possible to format the string sanely, as the column is a varchar(20).
# The 'v' character is added to the front of the string, so that any version
# formatted by this new function will sort _after_ any existing 200... strings.
my @tm = gettimeofday();
my @dt = gmtime ($tm[0]);
- my $o = $vtable->create({
+ my $o = $vtable->create({
version => $version,
installed => sprintf("v%04d%02d%02d_%02d%02d%02d.%03.0f",
$dt[5] + 1900,
use IO::File;
use DBIx::Class::Storage::TxnScopeGuard;
use Try::Tiny;
+use namespace::clean;
__PACKAGE__->mk_group_accessors('simple' => qw/debug debugobj schema/);
__PACKAGE__->mk_group_accessors('inherited' => 'cursor_class');
written to the file C</path/name>.
This environment variable is checked when the storage object is first
-created (when you call connect on your schema). So, run-time changes
-to this environment variable will not take effect unless you also
+created (when you call connect on your schema). So, run-time changes
+to this environment variable will not take effect unless you also
re-connect on your schema.
=head2 DBIX_CLASS_STORAGE_DBI_DEBUG
use Sub::Name ();
use Try::Tiny;
use File::Path ();
+use namespace::clean;
__PACKAGE__->mk_group_accessors('simple' =>
qw/_connect_info _dbi_connect_info _dbh _sql_maker _sql_maker_opts _conn_pid
$sth->finish
}
catch {
- $err = shift unless defined $err
+ $err = shift unless defined $err
};
};
use base 'DBIx::Class::Storage::DBI';
use Try::Tiny;
+use namespace::clean;
sub _rebless {
my $self = shift;
use base qw/DBIx::Class::Cursor/;
use Try::Tiny;
+use namespace::clean;
__PACKAGE__->mk_group_accessors('simple' =>
qw/sth/
use mro 'c3';
use List::Util();
use Try::Tiny;
+use namespace::clean;
=head1 NAME
}
$self->throw_exception('No sequence to fetch') unless $sequence;
-
+
my ($val) = $self->_get_dbh->selectrow_array(
'SELECT GEN_ID(' . $self->sql_maker->_quote($sequence) .
', 1) FROM rdb$database');
return $val;
-}
+}
sub _dbh_get_autoinc_seq {
my ($self, $dbh, $source, $col) = @_;
use base qw/DBIx::Class::Storage::DBI::UniqueIdentifier/;
use mro 'c3';
use Try::Tiny;
+use namespace::clean;
use List::Util();
if (
$sql !~ /^ \s* SELECT \s+ TOP \s+ \d+ \s+ /xi
&&
- scalar $self->_parse_order_by ($attrs->{order_by})
+ scalar $self->_parse_order_by ($attrs->{order_by})
) {
$self->throw_exception(
'An ordered subselect encountered - this is not safe! Please see "Ordered Subselects" in DBIx::Class::Storage::DBI::MSSQL
sub datetime_parser_type {
'DBIx::Class::Storage::DBI::MSSQL::DateTime::Format'
-}
+}
sub sqlt_type { 'SQLServer' }
package # hide from PAUSE
DBIx::Class::Storage::DBI::MSSQL::DateTime::Format;
-my $datetime_format = '%Y-%m-%d %H:%M:%S.%3N'; # %F %T
+my $datetime_format = '%Y-%m-%d %H:%M:%S.%3N'; # %F %T
my $smalldatetime_format = '%Y-%m-%d %H:%M:%S';
my ($datetime_parser, $smalldatetime_parser);
use base qw/DBIx::Class::Storage::DBI/;
use mro 'c3';
use Try::Tiny;
+use namespace::clean;
sub _rebless {
my ($self) = @_;
use List::Util();
use Scalar::Util ();
use Try::Tiny;
+use namespace::clean;
__PACKAGE__->mk_group_accessors(simple => qw/
_using_dynamic_cursors
use base qw/DBIx::Class::Storage::DBI/;
use mro 'c3';
use Try::Tiny;
+use namespace::clean;
sub _rebless {
my ($self) = @_;
use Scope::Guard ();
use Context::Preserve ();
use Try::Tiny;
+use namespace::clean;
=head1 NAME
my $txn_scope_guard = $self->txn_scope_guard;
$self->_do_query('alter session set constraints = deferred');
-
+
my $sg = Scope::Guard->new(sub {
$self->_do_query('alter session set constraints = immediate');
});
use Hash::Merge;
use List::Util qw/min max reduce/;
use Try::Tiny;
+use namespace::clean;
use namespace::clean -except => 'meta';
$schema->storage_type( ['::DBI::Replicated', {balancer=>'::Random'}] );
$schema->connection(...);
-Next, you need to add in the Replicants. Basically this is an array of
+Next, you need to add in the Replicants. Basically this is an array of
arrayrefs, where each arrayref is database connect information. Think of these
arguments as what you'd pass to the 'normal' $schema->connect method.
my $RS = $schema->resultset('Source')->search(undef, {force_pool=>'master'});
Now $RS will force everything (both reads and writes) to use whatever was setup
-as the master storage. 'master' is hardcoded to always point to the Master,
+as the master storage. 'master' is hardcoded to always point to the Master,
but you can also use any Replicant name. Please see:
L<DBIx::Class::Storage::DBI::Replicated::Pool> and the replicants attribute for more.
=head2 pool_type
-Contains the classname which will instantiate the L</pool> object. Defaults
+Contains the classname which will instantiate the L</pool> object. Defaults
to: L<DBIx::Class::Storage::DBI::Replicated::Pool>.
=cut
=head2 balancer
-Is a <DBIx::Class::Storage::DBI::Replicated::Balancer> or derived class. This
+Is a <DBIx::Class::Storage::DBI::Replicated::Balancer> or derived class. This
is a class that takes a pool (<DBIx::Class::Storage::DBI::Replicated::Pool>)
=cut
=head1 ATTRIBUTES IMPLEMENTING THE DBIx::Storage::DBI INTERFACE
-The following methods are delegated all the methods required for the
+The following methods are delegated all the methods required for the
L<DBIx::Class::Storage::DBI> interface.
=head2 read_handler
select
select_single
columns_info_for
- _dbh_columns_info_for
+ _dbh_columns_info_for
_select
/],
);
=cut
sub BUILDARGS {
- my ($class, $schema, $storage_type_args, @args) = @_;
+ my ($class, $schema, $storage_type_args, @args) = @_;
return {
schema=>$schema,
my $reliably = sub {
my $name = shift @_;
$schema->resultset('User')->create({name=>$name});
- my $user_rs = $schema->resultset('User')->find({name=>$name});
+ my $user_rs = $schema->resultset('User')->find({name=>$name});
return $user_rs;
};
my $self = shift;
return max map $_->lag_behind_master, $self->replicants;
-}
+}
=head2 is_replicating
sub _driver_determined {
my $self = shift;
-
+
if (@_) {
$_->_driver_determined(@_) for $self->all_storages;
}
sub _init {
my $self = shift;
-
+
$_->_init for $self->all_storages;
}
sub _run_connection_actions {
my $self = shift;
-
+
$_->_run_connection_actions for $self->all_storages;
}
sub _do_connection_actions {
my $self = shift;
-
+
if (@_) {
$_->_do_connection_actions(@_) for $self->all_storages;
}
if (not $self->_server_info_hash) {
my $min_version_info = (
- reduce { $a->[0] < $b->[0] ? $a : $b }
+ reduce { $a->[0] < $b->[0] ? $a : $b }
map [ $numify_ver->($_->{dbms_version}), $_ ],
map $_->_server_info, $self->all_storages
)->[1];
use Scalar::Util 'reftype';
requires qw/_query_start/;
-use namespace::clean -except => 'meta';
use Try::Tiny;
+use namespace::clean -except => 'meta';
=head1 NAME
use mro 'c3';
use List::Util ();
use Try::Tiny;
+use namespace::clean;
__PACKAGE__->mk_group_accessors(simple => qw/
_identity
my ($source, $to_insert) = @_;
my $identity_col = List::Util::first {
- $source->column_info($_)->{is_auto_increment}
+ $source->column_info($_)->{is_auto_increment}
} $source->columns;
# user might have an identity PK without is_auto_increment
use strict;
use warnings;
use Try::Tiny;
+use namespace::clean;
use base qw/DBIx::Class::Storage::DBI/;
use Sub::Name();
use Data::Dumper::Concise();
use Try::Tiny;
+use namespace::clean;
__PACKAGE__->mk_group_accessors('simple' =>
qw/_identity _blob_log_on_update _writer_storage _is_extra_storage
use warnings;
use Carp::Clan qw/^DBIx::Class/;
use Try::Tiny;
+use namespace::clean;
sub new {
my ($class, $storage) = @_;
=head1 DESCRIPTION
An object that behaves much like L<Scope::Guard>, but hardcoded to do the
-right thing with transactions in DBIx::Class.
+right thing with transactions in DBIx::Class.
=head1 METHODS
use Carp::Clan qw/^SQL::Translator|^DBIx::Class|^Try::Tiny/;
use Scalar::Util ();
use Try::Tiny;
+use namespace::clean;
use base qw(Exporter);
$dbicschema->throw_exception ("'sources' parameter must be an array or hash ref")
unless( $ref eq 'ARRAY' || ref eq 'HASH' );
- # limit monikers to those specified in
+ # limit monikers to those specified in
my $sources;
if ($ref eq 'ARRAY') {
$sources->{$_} = 1 for (@$limit_sources);
# Force the order of @cond to match the order of ->add_columns
my $idx;
my %other_columns_idx = map {'foreign.'.$_ => ++$idx } $relsource->columns;
- my @cond = sort { $other_columns_idx{$a} cmp $other_columns_idx{$b} } keys(%{$rel_info->{cond}});
+ my @cond = sort { $other_columns_idx{$a} cmp $other_columns_idx{$b} } keys(%{$rel_info->{cond}});
# Get the key information, mapping off the foreign/self markers
my @refkeys = map {/^\w+\.(\w+)$/} @cond;