| 1 | package DBIx::Class::ResultSource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 308 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 308 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 308 | ▶ | use base qw/DBIx::Class::ResultSource::RowParser DBIx::Class/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 308 | ▶ | use DBIx::Class::ResultSet; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 308 | ▶ | use DBIx::Class::ResultSourceHandle; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 308 | ▶ | use DBIx::Class::Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 308 | ▶ | use Devel::GlobalDestruction; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 308 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 308 | ▶ | use List::Util 'first'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 308 | ▶ | use Scalar::Util qw/blessed weaken isweak/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 308 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 308 | __PACKAGE__->mk_group_accessors(simple => qw/ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | source_name name source_info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | _ordered_columns _columns _primaries _unique_constraints | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | _relationships resultset_attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | column_info_from_storage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | /); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 308 | __PACKAGE__->mk_group_accessors(component_class => qw/ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | resultset_class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | result_class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | /); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 308 | __PACKAGE__->mk_classdata( sqlt_deploy_callback => 'default_sqlt_deploy_hook' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | DBIx::Class::ResultSource - Result source object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # Create a table based result source, in a result class. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | package MyApp::Schema::Result::Artist; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | use base qw/DBIx::Class::Core/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | __PACKAGE__->table('artist'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | __PACKAGE__->add_columns(qw/ artistid name /); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | __PACKAGE__->set_primary_key('artistid'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | __PACKAGE__->has_many(cds => 'MyApp::Schema::Result::CD'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # Create a query (view) based result source, in a result class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | package MyApp::Schema::Result::Year2000CDs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | use base qw/DBIx::Class::Core/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | __PACKAGE__->load_components('InflateColumn::DateTime'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | __PACKAGE__->table_class('DBIx::Class::ResultSource::View'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | __PACKAGE__->table('year2000cds'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | __PACKAGE__->result_source_instance->is_virtual(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | __PACKAGE__->result_source_instance->view_definition( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | "SELECT cdid, artist, title FROM cd WHERE year ='2000'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | A ResultSource is an object that represents a source of data for querying. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | This class is a base class for various specialised types of result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | sources, for example L<DBIx::Class::ResultSource::Table>. Table is the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | default result source type, so one is created for you when defining a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | result class as described in the synopsis above. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | More specifically, the L<DBIx::Class::Core> base class pulls in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | L<DBIx::Class::ResultSourceProxy::Table> component, which defines | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | the L<table|DBIx::Class::ResultSourceProxy::Table/table> method. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | When called, C<table> creates and stores an instance of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | L<DBIx::Class::ResultSoure::Table>. Luckily, to use tables as result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | sources, you don't need to remember any of this. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | Result sources representing select queries, or views, can also be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | created, see L<DBIx::Class::ResultSource::View> for full details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | =head2 Finding result source objects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | As mentioned above, a result source instance is created and stored for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | you when you define a L<result class|DBIx::Class::Manual::Glossary/Result class>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | You can retrieve the result source at runtime in the following ways: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | =item From a Schema object: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | $schema->source($source_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | =item From a Result object: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | $result->result_source; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | =item From a ResultSet object: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | $rs->result_source; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 117282 | ▶ | my ($class, $attrs) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 117282 | ▶ | $class = ref $class if ref $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 117282 | ▶ | my $new = bless { %{$attrs || {}} }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 117282 | ▶ | $new->{resultset_class} ||= 'DBIx::Class::ResultSet'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$new->{"resultset_class"} ||= "DBIx::Class::ResultSet"
MC/DC100%1/1
$new->{"resultset_class"} ||= "DBIx::Class::ResultSet"
$new->{"resultset_class"}
Truth table100%2/2
A
A= $new->{"resultset_class"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 117282 | ▶ | $new->{resultset_attributes} = { %{$new->{resultset_attributes} || {}} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 117282 | ▶ | $new->{_ordered_columns} = [ @{$new->{_ordered_columns}||[]}]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 117282 | ▶ | $new->{_columns} = { %{$new->{_columns}||{}} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 117282 | ▶ | $new->{_relationships} = { %{$new->{_relationships}||{}} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 117282 | ▶ | $new->{name} ||= "!!NAME NOT SET!!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$new->{"name"} ||= "!!NAME NOT SET!!"
MC/DC0%0/1
$new->{"name"} ||= "!!NAME NOT SET!!"
$new->{"name"}
Truth table50%1/2
A
A= $new->{"name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 117282 | ▶ | $new->{_columns_info_loaded} ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$new->{"_columns_info_loaded"} ||= 0
MC/DC0%0/1
$new->{"_columns_info_loaded"} ||= 0
$new->{"_columns_info_loaded"}
Truth table50%1/2
A
A= $new->{"_columns_info_loaded"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 117282 | return $new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | =head2 add_columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | =item Arguments: @columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | =item Return Value: L<$result_source|/new> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | $source->add_columns(qw/col1 col2 col3/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | $source->add_columns('col1' => \%col1_info, 'col2' => \%col2_info, ...); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | Adds columns to the result source. If supplied colname => hashref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | pairs, uses the hashref as the L</column_info> for that column. Repeated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | calls of this method will add more columns, not replace them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | The column names given will be created as accessor methods on your | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | L<Result|DBIx::Class::Manual::ResultClass> objects. You can change the name of the accessor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | by supplying an L</accessor> in the column_info hash. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | If a column name beginning with a plus sign ('+col1') is provided, the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | attributes provided will be merged with any existing attributes for the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | column, with the new attributes taking precedence in the case that an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | attribute already exists. Using this without a hashref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | (C<< $source->add_columns(qw/+col1 +col2/) >>) is legal, but useless -- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | it does the same thing it would do without the plus. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | The contents of the column_info are not set in stone. The following | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | keys are currently recognised/used by DBIx::Class: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | =item accessor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | { accessor => '_name' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # example use, replace standard accessor with one of your own: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | sub name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | my ($self, $value) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | die "Name cannot contain digits!" if($value =~ /\d/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | $self->_name($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | return $self->_name(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | Use this to set the name of the accessor method for this column. If unset, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | the name of the column will be used. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | =item data_type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | { data_type => 'integer' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | This contains the column type. It is automatically filled if you use the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | L<SQL::Translator::Producer::DBIx::Class::File> producer, or the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | L<DBIx::Class::Schema::Loader> module. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | Currently there is no standard set of values for the data_type. Use | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | whatever your database supports. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | =item size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | { size => 20 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | The length of your column, if it is a column type that can have a size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | restriction. This is currently only used to create tables from your | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | schema, see L<DBIx::Class::Schema/deploy>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | =item is_nullable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | { is_nullable => 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | Set this to a true value for a columns that is allowed to contain NULL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | values, default is false. This is currently only used to create tables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | from your schema, see L<DBIx::Class::Schema/deploy>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | =item is_auto_increment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | { is_auto_increment => 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | Set this to a true value for a column whose value is somehow | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | automatically set, defaults to false. This is used to determine which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | columns to empty when cloning objects using | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | L<DBIx::Class::Row/copy>. It is also used by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | L<DBIx::Class::Schema/deploy>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | =item is_numeric | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | { is_numeric => 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | Set this to a true or false value (not C<undef>) to explicitly specify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | if this column contains numeric data. This controls how set_column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | decides whether to consider a column dirty after an update: if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | C<is_numeric> is true a numeric comparison C<< != >> will take place | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | instead of the usual C<eq> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | If not specified the storage class will attempt to figure this out on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | first access to the column, based on the column C<data_type>. The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | result will be cached in this attribute. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | =item is_foreign_key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | { is_foreign_key => 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | Set this to a true value for a column that contains a key from a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | foreign table, defaults to false. This is currently only used to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | create tables from your schema, see L<DBIx::Class::Schema/deploy>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | =item default_value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | { default_value => \'now()' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | Set this to the default value which will be inserted into a column by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | the database. Can contain either a value or a function (use a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | reference to a scalar e.g. C<\'now()'> if you want a function). This | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | is currently only used to create tables from your schema, see | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | L<DBIx::Class::Schema/deploy>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | See the note on L<DBIx::Class::Row/new> for more information about possible | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | issues related to db-side default values. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | =item sequence | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | { sequence => 'my_table_seq' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | Set this on a primary key column to the name of the sequence used to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | generate a new key value. If not specified, L<DBIx::Class::PK::Auto> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | will attempt to retrieve the name of the sequence from the database | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | automatically. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | =item retrieve_on_insert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | { retrieve_on_insert => 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | For every column where this is set to true, DBIC will retrieve the RDBMS-side | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | value upon a new row insertion (normally only the autoincrement PK is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | retrieved on insert). C<INSERT ... RETURNING> is used automatically if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | supported by the underlying storage, otherwise an extra SELECT statement is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | executed to retrieve the missing data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | =item auto_nextval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | { auto_nextval => 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | Set this to a true value for a column whose value is retrieved automatically | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | from a sequence or function (if supported by your Storage driver.) For a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | sequence, if you do not use a trigger to get the nextval, you have to set the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | L</sequence> value as well. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | Also set this for MSSQL columns with the 'uniqueidentifier' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | L<data_type|DBIx::Class::ResultSource/data_type> whose values you want to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | automatically generate using C<NEWID()>, unless they are a primary key in which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | case this will be done anyway. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | =item extra | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | This is used by L<DBIx::Class::Schema/deploy> and L<SQL::Translator> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | to add extra non-generic data to the column. For example: C<< extra | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | => { unsigned => 1} >> is used by the MySQL producer to set an integer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | column to unsigned. For more details, see | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | L<SQL::Translator::Producer::MySQL>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | =head2 add_column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | =item Arguments: $colname, \%columninfo? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | =item Return Value: 1/0 (true/false) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | $source->add_column('col' => \%info); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | Add a single column and optional column info. Uses the same column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | info keys as L</add_columns>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | sub add_columns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 13417 | ▶ | my ($self, @cols) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_columns: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 13417 | ▶ | $self->_ordered_columns(\@cols) unless $self->_ordered_columns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 13417 | my @added; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 13417 | my $columns = $self->_columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 13417 | ▶ | while (my $col = shift @cols) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 42886 | my $column_info = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 42886 | ▶ | if ($col =~ s/^\+//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 617 | $column_info = $self->column_info($col); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | # If next entry is { ... } use that for the column info, if not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | # use an empty hashref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 42886 | ▶ | if (ref $cols[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 42848 | my $new_info = shift(@cols); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 42848 | %$column_info = (%$column_info, %$new_info); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 42886 | ▶ | push(@added, $col) unless exists $columns->{$col}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 42886 | $columns->{$col} = $column_info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 13417 | push @{ $self->_ordered_columns }, @added; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 13417 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 1 | ▶ | sub add_column { shift->add_columns(@_); } # DO NOT CHANGE THIS TO GLOB | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_column: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | =head2 has_column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | =item Arguments: $colname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | =item Return Value: 1/0 (true/false) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | if ($source->has_column($colname)) { ... } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | Returns true if the source has a column of this name, false otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | sub has_column { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 71172 | ▶ | my ($self, $column) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_column: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 71172 | return exists $self->_columns->{$column}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | =head2 column_info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | =item Arguments: $colname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | =item Return Value: Hashref of info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | my $info = $source->column_info($col); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | Returns the column metadata hashref for a column, as originally passed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | to L</add_columns>. See L</add_columns> above for information on the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | contents of the hashref. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | sub column_info { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 56036 | ▶ | my ($self, $column) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
column_info: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | $self->throw_exception("No such column $column") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 56036 | ▶ | unless exists $self->_columns->{$column}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 56036 | ▶ | if ( ! $self->_columns->{$column}{data_type} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
not $self->_columns->{$column}{"data_type"} || $self->{"_columns_info_loaded"} and $self->column_info_from_storage and my $stor = &try(sub {
$self->storage;
}
)
not $self->_columns->{$column}{"data_type"} || $self->{"_columns_info_loaded"} and $self->column_info_from_storage
$self->_columns->{$column}{'data_type'} || $self->{'_columns_info_loaded'}
MC/DC50%2/4
not $self->_columns->{$column}{"data_type"} || $self->{"_columns_info_loaded"} and $self->column_info_from_storage and my $stor = &try(sub {
$self->storage;
}
)
$self->_columns->{$column}{'data_type'}
$self->{'_columns_info_loaded'}
$self->column_info_from_storage
my $stor = &try(sub {
$self->storage;
}
)
Truth table60%3/5
not(A || B) and C and D
A= $self->_columns->{$column}{'data_type'}B= $self->{'_columns_info_loaded'}C= $self->column_info_from_storageD= my $stor = &try(sub {
$self->storage;
}
)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | and ! $self->{_columns_info_loaded} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | and $self->column_info_from_storage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 1 | ▶ | and my $stor = try { $self->storage } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 1 | $self->{_columns_info_loaded}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | # try for the case of storage without table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 1 | ▶ | my $info = $stor->columns_info_for( $self->from ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | my $lc_info = { map | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 1 | { (lc $_) => $info->{$_} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | ( keys %$info ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 1 | foreach my $col ( keys %{$self->_columns} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | $self->_columns->{$col} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 4 | %{ $self->_columns->{$col} }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 4 | ▶ | %{ $info->{$col} || $lc_info->{lc $col} || {} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$info->{$col} or $$lc_info{lc $col}
MC/DC0%0/2
$info->{$col} or $$lc_info{lc $col}
$info->{$col}
$$lc_info{lc $col}
Truth table33%1/3
A or B
A= $info->{$col}B= $$lc_info{lc $col}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 56036 | return $self->_columns->{$column}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | =head2 columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | =item Arguments: none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | =item Return Value: Ordered list of column names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | my @column_names = $source->columns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | Returns all column names in the order they were declared to L</add_columns>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | sub columns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 19840 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
columns: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 19840 | ▶ | $self->throw_exception( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | "columns() is a read-only accessor, did you mean add_columns()?" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | ) if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 19839 | ▶ | return @{$self->{_ordered_columns}||[]}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | =head2 columns_info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | =item Arguments: \@colnames ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | =item Return Value: Hashref of column name/info pairs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | my $columns_info = $source->columns_info; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | Like L</column_info> but returns information for the requested columns. If | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | the optional column-list arrayref is omitted it returns info on all columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | currently defined on the ResultSource via L</add_columns>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | sub columns_info { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 43035 | ▶ | my ($self, $columns) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
columns_info: called CC=10 SCAR=23.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 43035 | my $colinfo = $self->_columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 43035 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
&first(sub {
not $_->{"data_type"};
}
, values %$colinfo) and not $self->{"_columns_info_loaded"} and $self->column_info_from_storage and my $stor = &try(sub {
$self->storage;
}
)
&first(sub {
not $_->{"data_type"};
}
, values %$colinfo) and not $self->{"_columns_info_loaded"} and $self->column_info_from_storage
&first(sub {
not $_->{"data_type"};
}
, values %$colinfo) and not $self->{"_columns_info_loaded"}
MC/DC75%3/4
&first(sub {
not $_->{"data_type"};
}
, values %$colinfo) and not $self->{"_columns_info_loaded"} and $self->column_info_from_storage and my $stor = &try(sub {
$self->storage;
}
)
&first(sub {
not $_->{"data_type"};
}
, values %$colinfo)
not $self->{"_columns_info_loaded"}
$self->column_info_from_storage
my $stor = &try(sub {
$self->storage;
}
)
Truth table80%4/5
A and not(B) and C and D
A= &first(sub {
not $_->{"data_type"};
}
, values %$colinfo)B= not $self->{"_columns_info_loaded"}C= $self->column_info_from_storageD= my $stor = &try(sub {
$self->storage;
}
)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 168132 | ▶ | first { ! $_->{data_type} } values %$colinfo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | ! $self->{_columns_info_loaded} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | $self->column_info_from_storage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 3 | ▶ | my $stor = try { $self->storage } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 1 | $self->{_columns_info_loaded}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | # try for the case of storage without table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 1 | ▶ | my $info = $stor->columns_info_for( $self->from ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | my $lc_info = { map | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 1 | { (lc $_) => $info->{$_} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | ( keys %$info ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 1 | foreach my $col ( keys %$colinfo ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | $colinfo->{$col} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 4 | %{ $colinfo->{$col} }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 4 | ▶ | %{ $info->{$col} || $lc_info->{lc $col} || {} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$info->{$col} or $$lc_info{lc $col}
MC/DC0%0/2
$info->{$col} or $$lc_info{lc $col}
$info->{$col}
$$lc_info{lc $col}
Truth table33%1/3
A or B
A= $info->{$col}B= $$lc_info{lc $col}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 43035 | my %ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 43035 | ▶ | if ($columns) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 20658 | for (@$columns) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 39714 | ▶ | if (my $inf = $colinfo->{$_}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 39713 | $ret{$_} = $inf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 1 | ▶ | $self->throw_exception( sprintf ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$self->source_name || $self->name || 'Unknown source...?'
$self->source_name or $self->name
MC/DC0%0/2
$self->source_name || $self->name || 'Unknown source...?'
$self->source_name
$self->name
Truth table33%1/3
A or B
A= $self->source_nameB= $self->name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | "No such column '%s' on source '%s'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | $_, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | $self->source_name || $self->name || 'Unknown source...?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 22377 | %ret = %$colinfo; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 43034 | return \%ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | =head2 remove_columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | =item Arguments: @colnames | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | =item Return Value: not defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | $source->remove_columns(qw/col1 col2 col3/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | Removes the given list of columns by name, from the result source. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | B<Warning>: Removing a column that is also used in the sources primary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | key, or in one of the sources unique constraints, B<will> result in a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | broken result source. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | =head2 remove_column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | =item Arguments: $colname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | =item Return Value: not defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | $source->remove_column('col'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | Remove a single column by name from the result source, similar to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | L</remove_columns>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | B<Warning>: Removing a column that is also used in the sources primary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | key, or in one of the sources unique constraints, B<will> result in a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | broken result source. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | sub remove_columns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 2 | ▶ | my ($self, @to_remove) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove_columns: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 2 | ▶ | my $columns = $self->_columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 2 | my %to_remove; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 2 | for (@to_remove) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 3 | delete $columns->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 3 | ++$to_remove{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 2 | $self->_ordered_columns([ grep { not $to_remove{$_} } @{$self->_ordered_columns} ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | ▶ | sub remove_column { shift->remove_columns(@_); } # DO NOT CHANGE THIS TO GLOB | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove_column: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | =head2 set_primary_key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | =item Arguments: @cols | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | =item Return Value: not defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | Defines one or more columns as primary key for this source. Must be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | called after L</add_columns>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | Additionally, defines a L<unique constraint|add_unique_constraint> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | named C<primary>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | Note: you normally do want to define a primary key on your sources | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | B<even if the underlying database table does not have a primary key>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | See | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | L<DBIx::Class::Manual::Intro/The Significance and Importance of Primary Keys> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | for more info. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | sub set_primary_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 12776 | ▶ | my ($self, @cols) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_primary_key: called CC=5 SCAR=16.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 12776 | my $colinfo = $self->columns_info(\@cols); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 12775 | for my $col (@cols) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | carp_unique(sprintf ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | "Primary key of source '%s' includes the column '%s' which has its " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | . "'is_nullable' attribute set to true. This is a mistake and will cause " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | . 'various Result-object operations to fail', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | $self->source_name || $self->name || 'Unknown source...?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | $col, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 17705 | ▶ | )) if $colinfo->{$col}{is_nullable}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition40%2/5
$self->source_name || $self->name || 'Unknown source...?'
$self->source_name or $self->name
MC/DC0%0/2
$self->source_name || $self->name || 'Unknown source...?'
$self->source_name
$self->name
Truth table33%1/3
A or B
A= $self->source_nameB= $self->name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 12775 | $self->_primaries(\@cols); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 12775 | $self->add_unique_constraint(primary => \@cols); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | =head2 primary_columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | =item Arguments: none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | =item Return Value: Ordered list of primary column names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | Read-only accessor which returns the list of primary keys, supplied by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | L</set_primary_key>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | sub primary_columns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 30482 | ▶ | return @{shift->_primaries||[]}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
primary_columns: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | # a helper method that will automatically die with a descriptive message if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | # no pk is defined on the source in question. For internal use to save | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | # on if @pks... boilerplate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | sub _pri_cols_or_die { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 19724 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pri_cols_or_die: called CC=5 SCAR=18.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 19724 | ▶ | my @pcols = $self->primary_columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition37%3/8
$self->source_name || $self->result_class || $self->name || 'Unknown source...?'
$self->source_name or $self->result_class or $self->name
$self->source_name or $self->result_class
MC/DC0%0/3
$self->source_name || $self->result_class || $self->name || 'Unknown source...?'
$self->source_name
$self->result_class
$self->name
Truth table25%1/4
A or B or C
A= $self->source_nameB= $self->result_classC= $self->name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | or $self->throw_exception (sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | "Operation requires a primary key to be declared on '%s' via set_primary_key", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | # source_name is set only after schema-registration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | $self->source_name || $self->result_class || $self->name || 'Unknown source...?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 19722 | return @pcols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | # same as above but mandating single-column PK (used by relationship condition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | # inferrence) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | sub _single_pri_col_or_die { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 16955 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_single_pri_col_or_die: called CC=5 SCAR=24.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 16955 | my ($pri, @too_many) = $self->_pri_cols_or_die; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 16955 | ▶ | $self->throw_exception( sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/8
$self->source_name || $self->result_class || $self->name || 'Unknown source...?'
$self->source_name or $self->result_class or $self->name
$self->source_name or $self->result_class
MC/DC0%0/3
$self->source_name || $self->result_class || $self->name || 'Unknown source...?'
$self->source_name
$self->result_class
$self->name
Truth table0%0/4
A or B or C
A= $self->source_nameB= $self->result_classC= $self->name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | "Operation requires a single-column primary key declared on '%s'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | $self->source_name || $self->result_class || $self->name || 'Unknown source...?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | )) if @too_many; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 16955 | return $pri; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | =head2 sequence | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | Manually define the correct sequence for your table, to avoid the overhead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | associated with looking up the sequence automatically. The supplied sequence | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | will be applied to the L</column_info> of each L<primary_key|/set_primary_key> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | =item Arguments: $sequence_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | =item Return Value: not defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | sub sequence { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 308 | ▶ | my ($self,$seq) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sequence: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 308 | ▶ | my @pks = $self->primary_columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | $_->{sequence} = $seq | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 308 | for values %{ $self->columns_info (\@pks) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | =head2 add_unique_constraint | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | =item Arguments: $name?, \@colnames | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | =item Return Value: not defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | Declare a unique constraint on this source. Call once for each unique | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | constraint. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | # For UNIQUE (column1, column2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | __PACKAGE__->add_unique_constraint( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | constraint_name => [ qw/column1 column2/ ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | Alternatively, you can specify only the columns: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | __PACKAGE__->add_unique_constraint([ qw/column1 column2/ ]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | This will result in a unique constraint named | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | C<table_column1_column2>, where C<table> is replaced with the table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | Unique constraints are used, for example, when you pass the constraint | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | name as the C<key> attribute to L<DBIx::Class::ResultSet/find>. Then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | only columns in the constraint are searched. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | Throws an error if any of the given column names do not yet exist on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | the result source. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | sub add_unique_constraint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 18420 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_unique_constraint: called CC=7 SCAR=20.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 18420 | ▶ | if (@_ > 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 1 | $self->throw_exception( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 'add_unique_constraint() does not accept multiple constraints, use ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | . 'add_unique_constraints() instead' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 18419 | my $cols = pop @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 18419 | ▶ | if (ref $cols ne 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | ▶ | $self->throw_exception ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$cols || 'NOTHING'
MC/DC0%0/1
$cols || 'NOTHING'
$cols
Truth table0%0/2
A
A= $cols
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 'Expecting an arrayref of constraint columns, got ' . ($cols||'NOTHING') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 18419 | my $name = shift @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 18419 | ▶ | $name ||= $self->name_unique_constraint($cols); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$name ||= $self->name_unique_constraint($cols)
MC/DC0%0/2
$name ||= $self->name_unique_constraint($cols)
$name
$self->name_unique_constraint($cols)
Truth table66%2/3
A ||= B
A= $nameB= $self->name_unique_constraint($cols)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 18419 | foreach my $col (@$cols) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 27353 | ▶ | $self->throw_exception("No such column $col on table " . $self->name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | unless $self->has_column($col); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 18419 | my %unique_constraints = $self->unique_constraints; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 18419 | $unique_constraints{$name} = $cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 18419 | $self->_unique_constraints(\%unique_constraints); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | =head2 add_unique_constraints | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | =item Arguments: @constraints | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | =item Return Value: not defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | Declare multiple unique constraints on this source. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | __PACKAGE__->add_unique_constraints( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | constraint_name1 => [ qw/column1 column2/ ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | constraint_name2 => [ qw/column2 column3/ ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | Alternatively, you can specify only the columns: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | __PACKAGE__->add_unique_constraints( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | [ qw/column1 column2/ ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | [ qw/column3 column4/ ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | This will result in unique constraints named C<table_column1_column2> and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | C<table_column3_column4>, where C<table> is replaced with the table name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | Throws an error if any of the given column names do not yet exist on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | the result source. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | See also L</add_unique_constraint>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | sub add_unique_constraints { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 616 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_unique_constraints: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 616 | my @constraints = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 616 | ▶ | if ( !(@constraints % 2) && first { ref $_ ne 'ARRAY' } @constraints ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
Condition66%2/3
not @constraints % 2 and &first(sub {
ref $_ ne "ARRAY";
}
, @constraints)
MC/DC50%1/2
not @constraints % 2 and &first(sub {
ref $_ ne "ARRAY";
}
, @constraints)
not @constraints % 2
&first(sub {
ref $_ ne "ARRAY";
}
, @constraints)
Truth table66%2/3
not(A) and B
A= not @constraints % 2B= &first(sub {
ref $_ ne "ARRAY";
}
, @constraints)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | # with constraint name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 308 | ▶ | while (my ($name, $constraint) = splice @constraints, 0, 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 616 | $self->add_unique_constraint($name => $constraint); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | # no constraint name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 308 | foreach my $constraint (@constraints) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 616 | $self->add_unique_constraint($constraint); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | =head2 name_unique_constraint | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | =item Arguments: \@colnames | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | =item Return Value: Constraint name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | $source->table('mytable'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | $source->name_unique_constraint(['col1', 'col2']); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | # returns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 'mytable_col1_col2' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | Return a name for a unique constraint containing the specified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | columns. The name is created by joining the table name and each column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | name, using an underscore character. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | For example, a constraint on a table named C<cd> containing the columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | C<artist> and C<title> would result in a constraint name of C<cd_artist_title>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | This is used by L</add_unique_constraint> if you do not specify the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | optional constraint name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | sub name_unique_constraint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 3180 | ▶ | my ($self, $cols) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name_unique_constraint: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 3180 | my $name = $self->name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 3180 | ▶ | $name = $$name if (ref $name eq 'SCALAR'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 3180 | return join '_', $name, @$cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | =head2 unique_constraints | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | =item Arguments: none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | =item Return Value: Hash of unique constraint data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | $source->unique_constraints(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | Read-only accessor which returns a hash of unique constraints on this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | source. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | The hash is keyed by constraint name, and contains an arrayref of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | column names as values. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | sub unique_constraints { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 27987 | ▶ | return %{shift->_unique_constraints||{}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unique_constraints: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | =head2 unique_constraint_names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | =item Arguments: none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | =item Return Value: Unique constraint names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | $source->unique_constraint_names(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | Returns the list of unique constraint names defined on this source. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | sub unique_constraint_names { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 1105 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unique_constraint_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 1105 | my %unique_constraints = $self->unique_constraints; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 1105 | return keys %unique_constraints; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | =head2 unique_constraint_columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | =item Arguments: $constraintname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | =item Return Value: List of constraint columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | $source->unique_constraint_columns('myconstraint'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | Returns the list of columns that make up the specified unique constraint. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | sub unique_constraint_columns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 6899 | ▶ | my ($self, $constraint_name) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unique_constraint_columns: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 6899 | my %unique_constraints = $self->unique_constraints; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | $self->throw_exception( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | "Unknown unique constraint $constraint_name on '" . $self->name . "'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 6899 | ▶ | ) unless exists $unique_constraints{$constraint_name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 6899 | return @{ $unique_constraints{$constraint_name} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | =head2 sqlt_deploy_callback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | =item Arguments: $callback_name | \&callback_code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | =item Return Value: $callback_name | \&callback_code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | __PACKAGE__->sqlt_deploy_callback('mycallbackmethod'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | __PACKAGE__->sqlt_deploy_callback(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | my ($source_instance, $sqlt_table) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | An accessor to set a callback to be called during deployment of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | the schema via L<DBIx::Class::Schema/create_ddl_dir> or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | L<DBIx::Class::Schema/deploy>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | The callback can be set as either a code reference or the name of a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | method in the current result class. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | Defaults to L</default_sqlt_deploy_hook>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | Your callback will be passed the $source object representing the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | ResultSource instance being deployed, and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | L<SQL::Translator::Schema::Table> object being created from it. The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | callback can be used to manipulate the table object or add your own | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | customised indexes. If you need to manipulate a non-table object, use | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | the L<DBIx::Class::Schema/sqlt_deploy_hook>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | See L<DBIx::Class::Manual::Cookbook/Adding Indexes And Functions To | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | Your SQL> for examples. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | This sqlt deployment callback can only be used to manipulate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | SQL::Translator objects as they get turned into SQL. To execute | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | post-deploy statements which SQL::Translator does not currently | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | handle, override L<DBIx::Class::Schema/deploy> in your Schema class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | and call L<dbh_do|DBIx::Class::Storage::DBI/dbh_do>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | =head2 default_sqlt_deploy_hook | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | This is the default deploy hook implementation which checks if your | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | current Result class has a C<sqlt_deploy_hook> method, and if present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | invokes it B<on the Result class directly>. This is to preserve the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | semantics of C<sqlt_deploy_hook> which was originally designed to expect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | the Result class name and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | L<$sqlt_table instance|SQL::Translator::Schema::Table> of the table being | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | deployed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | sub default_sqlt_deploy_hook { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_sqlt_deploy_hook: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | 0 | my $class = $self->result_class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | 0 | ▶ | if ($class and $class->can('sqlt_deploy_hook')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$class and $class->can("sqlt_deploy_hook")
MC/DC0%0/2
$class and $class->can("sqlt_deploy_hook")
$class
$class->can("sqlt_deploy_hook")
Truth table0%0/3
A and B
A= $classB= $class->can("sqlt_deploy_hook")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | 0 | $class->sqlt_deploy_hook(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | sub _invoke_sqlt_deploy_hook { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_invoke_sqlt_deploy_hook: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | 0 | ▶ | if ( my $hook = $self->sqlt_deploy_callback) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | 0 | $self->$hook(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | =head2 result_class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | =item Arguments: $classname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | =item Return Value: $classname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | use My::Schema::ResultClass::Inflator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | use My::Schema::Artist; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | __PACKAGE__->result_class('My::Schema::ResultClass::Inflator'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | Set the default result class for this source. You can use this to create | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | and use your own result inflator. See L<DBIx::Class::ResultSet/result_class> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | for more details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | Please note that setting this to something like | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | L<DBIx::Class::ResultClass::HashRefInflator> will make every result unblessed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | and make life more difficult. Inflators like those are better suited to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | temporary usage via L<DBIx::Class::ResultSet/result_class>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | =head2 resultset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | =item Arguments: none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | =item Return Value: L<$resultset|DBIx::Class::ResultSet> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | Returns a resultset for the given source. This will initially be created | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | on demand by calling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | $self->resultset_class->new($self, $self->resultset_attributes) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | but is cached from then on unless resultset_class changes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | =head2 resultset_class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | =item Arguments: $classname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | =item Return Value: $classname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | package My::Schema::ResultSet::Artist; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | use base 'DBIx::Class::ResultSet'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | # In the result class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | __PACKAGE__->resultset_class('My::Schema::ResultSet::Artist'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | # Or in code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | $source->resultset_class('My::Schema::ResultSet::Artist'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | Set the class of the resultset. This is useful if you want to create your | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | own resultset methods. Create your own class derived from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | L<DBIx::Class::ResultSet>, and set it here. If called with no arguments, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | this method returns the name of the existing resultset class, if one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | exists. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | =head2 resultset_attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | =item Arguments: L<\%attrs|DBIx::Class::ResultSet/ATTRIBUTES> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | =item Return Value: L<\%attrs|DBIx::Class::ResultSet/ATTRIBUTES> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | # In the result class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | __PACKAGE__->resultset_attributes({ order_by => [ 'id' ] }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | # Or in code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | $source->resultset_attributes({ order_by => [ 'id' ] }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | Store a collection of resultset attributes, that will be set on every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | L<DBIx::Class::ResultSet> produced from this result source. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | B<CAVEAT>: C<resultset_attributes> comes with its own set of issues and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | bugs! While C<resultset_attributes> isn't deprecated per se, its usage is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | not recommended! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | Since relationships use attributes to link tables together, the "default" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | attributes you set may cause unpredictable and undesired behavior. Furthermore, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | the defaults cannot be turned off, so you are stuck with them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | In most cases, what you should actually be using are project-specific methods: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | package My::Schema::ResultSet::Artist; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | use base 'DBIx::Class::ResultSet'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | # BAD IDEA! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | #__PACKAGE__->resultset_attributes({ prefetch => 'tracks' }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | # GOOD IDEA! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | sub with_tracks { shift->search({}, { prefetch => 'tracks' }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | # in your code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | $schema->resultset('Artist')->with_tracks->... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | This gives you the flexibility of not using it when you don't need it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | For more complex situations, another solution would be to use a virtual view | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | via L<DBIx::Class::ResultSource::View>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | sub resultset { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | 14200 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resultset: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | 14200 | ▶ | $self->throw_exception( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | 'resultset does not take any arguments. If you want another resultset, '. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | 'call it on the schema instead.' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | ) if scalar @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | $self->resultset_class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | $self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 14200 | ▶ | try { %{$self->schema->default_resultset_attributes} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | 14200 | %{$self->{resultset_attributes}}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | =head2 name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | =item Arguments: none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | =item Result value: $name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | Returns the name of the result source, which will typically be the table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | name. This may be a scalar reference if the result source has a non-standard | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | =head2 source_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | =item Arguments: $source_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | =item Result value: $source_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | Set an alternate name for the result source when it is loaded into a schema. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | This is useful if you want to refer to a result source by a name other than | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | its class name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | package ArchivedBooks; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | use base qw/DBIx::Class/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | __PACKAGE__->table('books_archive'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | __PACKAGE__->source_name('Books'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | # from your schema... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | $schema->resultset('Books')->find(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | =head2 from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | =item Arguments: none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | =item Return Value: FROM clause | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | my $from_clause = $source->from(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | Returns an expression of the source to be supplied to storage to specify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | retrieval from this source. In the case of a database, the required FROM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | clause contents. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | 0 | ▶ | sub from { die 'Virtual method!' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | =head2 schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | =item Arguments: L<$schema?|DBIx::Class::Schema> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | =item Return Value: L<$schema|DBIx::Class::Schema> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | my $schema = $source->schema(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | Sets and/or returns the L<DBIx::Class::Schema> object to which this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | result source instance has been attached to. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | sub schema { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | 118799 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
schema: called CC=5 SCAR=16.1
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | 67224 | $_[0]->{schema} = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | 51575 | ▶ | $_[0]->{schema} || do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | 85 | ▶ | my $name = $_[0]->{source_name} || '_unnamed_'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_[0]{'source_name'} || '_unnamed_'
MC/DC100%1/1
$_[0]{'source_name'} || '_unnamed_'
$_[0]{'source_name'}
Truth table100%2/2
A
A= $_[0]{'source_name'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | 85 | my $err = 'Unable to perform storage-dependent operations with a detached result source ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | . "(source '$name' is not associated with a schema)."; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | $err .= ' You need to use $schema->thaw() or manually set' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | . ' $DBIx::Class::ResultSourceHandle::thaw_schema while thawing.' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | 85 | ▶ | if $_[0]->{_detached_thaw}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | 85 | DBIx::Class::Exception->throw($err); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | =head2 storage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | =item Arguments: none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | =item Return Value: L<$storage|DBIx::Class::Storage> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | $source->storage->debug(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | Returns the L<storage handle|DBIx::Class::Storage> for the current schema. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | 19323 | ▶ | sub storage { shift->schema->storage; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
storage: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | =head2 add_relationship | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | =item Arguments: $rel_name, $related_source_name, \%cond, \%attrs? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | =item Return Value: 1/true if it succeeded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | $source->add_relationship('rel_name', 'related_source', $cond, $attrs); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | L<DBIx::Class::Relationship> describes a series of methods which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | create pre-defined useful types of relationships. Look there first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | before using this method directly. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | The relationship name can be arbitrary, but must be unique for each | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | relationship attached to this result source. 'related_source' should | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | be the name with which the related result source was registered with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | the current schema. For example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | $schema->source('Book')->add_relationship('reviews', 'Review', { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | 'foreign.book_id' => 'self.id', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | The condition C<$cond> needs to be an L<SQL::Abstract>-style | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | representation of the join between the tables. For example, if you're | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | creating a relation from Author to Book, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | { 'foreign.author_id' => 'self.id' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | will result in the JOIN clause | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | author me JOIN book foreign ON foreign.author_id = me.id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | You can specify as many foreign => self mappings as necessary. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | Valid attributes are as follows: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | =item join_type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | Explicitly specifies the type of join to use in the relationship. Any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | SQL join type is valid, e.g. C<LEFT> or C<RIGHT>. It will be placed in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | the SQL command immediately before C<JOIN>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | =item proxy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | An arrayref containing a list of accessors in the foreign class to proxy in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | the main class. If, for example, you do the following: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | CD->might_have(liner_notes => 'LinerNotes', undef, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | proxy => [ qw/notes/ ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | Then, assuming LinerNotes has an accessor named notes, you can do: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | my $cd = CD->find(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | # set notes -- LinerNotes object is created if it doesn't exist | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | $cd->notes('Notes go here'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | =item accessor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | Specifies the type of accessor that should be created for the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | relationship. Valid values are C<single> (for when there is only a single | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | related object), C<multi> (when there can be many), and C<filter> (for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | when there is a single related object, but you also want the relationship | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | accessor to double as a column accessor). For C<multi> accessors, an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | add_to_* method is also created, which calls C<create_related> for the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | relationship. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | Throws an exception if the condition is improperly supplied, or cannot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | be resolved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | sub add_relationship { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | 25617 | ▶ | my ($self, $rel, $f_source_name, $cond, $attrs) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_relationship: called CC=10 SCAR=30.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | 25617 | ▶ | $self->throw_exception("Can't create relationship without join condition") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | unless $cond; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | 25616 | ▶ | $attrs ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$attrs ||= {}
MC/DC100%1/1
$attrs ||= {}
$attrs
Truth table100%2/2
A
A= $attrs
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | # Check foreign and self are right in cond | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | 25616 | ▶ | if ( (ref $cond ||'') eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref $cond || ''
MC/DC0%0/1
ref $cond || ''
ref $cond
Truth table50%1/2
A
A= ref $cond
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | 22227 | for (keys %$cond) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | 24999 | ▶ | $self->throw_exception("Keys of condition should be of form 'foreign.col', not '$_'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
/\./ and not /^foreign\./
MC/DC0%0/2
/\./ and not /^foreign\./
/\./
not /^foreign\./
Truth table33%1/3
A and not(B)
A= /\./B= not /^foreign\./
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | if /\./ && !/^foreign\./; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | 25616 | my %rels = %{ $self->_relationships }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | 25616 | $rels{$rel} = { class => $f_source_name, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | source => $f_source_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | cond => $cond, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | attrs => $attrs }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | 25616 | $self->_relationships(\%rels); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | 25616 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | # XXX disabled. doesn't work properly currently. skip in tests. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | 0 | my $f_source = $self->schema->source($f_source_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | 0 | ▶ | unless ($f_source) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | 0 | $self->ensure_class_loaded($f_source_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | 0 | $f_source = $f_source_name->result_source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | #my $s_class = ref($self->schema); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | #$f_source_name =~ m/^${s_class}::(.*)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | #$self->schema->register_class(($1 || $f_source_name), $f_source_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | #$f_source = $self->schema->source($f_source_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | 0 | ▶ | return unless $f_source; # Can't test rel without f_source | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | 0 | ▶ | try { $self->_resolve_join($rel, 'me', {}, []) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1345 | catch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1346 | # If the resolve failed, back out and re-throw the error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1347 | 0 | ▶ | delete $rels{$rel}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1348 | 0 | $self->_relationships(\%rels); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1349 | 0 | $self->throw_exception("Error creating relationship $rel: $_"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1350 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1352 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1353 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1355 | =head2 relationships | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1357 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1359 | =item Arguments: none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1361 | =item Return Value: L<@rel_names|DBIx::Class::Relationship> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1363 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1365 | my @relnames = $source->relationships(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | Returns all relationship names for this source. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1369 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1371 | sub relationships { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1372 | 9260 | ▶ | return keys %{shift->_relationships}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
relationships: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1375 | =head2 relationship_info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1377 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1379 | =item Arguments: L<$rel_name|DBIx::Class::Relationship> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1381 | =item Return Value: L<\%rel_data|DBIx::Class::Relationship::Base/add_relationship> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1383 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1385 | Returns a hash of relationship information for the specified relationship | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1386 | name. The keys/values are as specified for L<DBIx::Class::Relationship::Base/add_relationship>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1387 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1388 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1389 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1390 | sub relationship_info { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1391 | #my ($self, $rel) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1392 | 88968 | ▶ | return shift->_relationships->{+shift}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
relationship_info: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1395 | =head2 has_relationship | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1397 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1399 | =item Arguments: L<$rel_name|DBIx::Class::Relationship> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1401 | =item Return Value: 1/0 (true/false) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1403 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1404 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1405 | Returns true if the source has a relationship of this name, false otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1407 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1409 | sub has_relationship { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1410 | #my ($self, $rel) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1411 | 13735 | ▶ | return exists shift->_relationships->{+shift}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_relationship: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1414 | =head2 reverse_relationship_info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1415 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1416 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1418 | =item Arguments: L<$rel_name|DBIx::Class::Relationship> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1419 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1420 | =item Return Value: L<\%rel_data|DBIx::Class::Relationship::Base/add_relationship> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1421 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1422 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1424 | Looks through all the relationships on the source this relationship | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1425 | points to, looking for one whose condition is the reverse of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1426 | condition on this relationship. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1428 | A common use of this is to find the name of the C<belongs_to> relation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1429 | opposing a C<has_many> relation. For definition of these look in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1430 | L<DBIx::Class::Relationship>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1432 | The returned hashref is keyed by the name of the opposing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1433 | relationship, and contains its data in the same manner as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1434 | L</relationship_info>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1435 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1436 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1438 | sub reverse_relationship_info { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1439 | 877 | ▶ | my ($self, $rel) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reverse_relationship_info: called CC=13 SCAR=25.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1440 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1441 | 877 | ▶ | my $rel_info = $self->relationship_info($rel) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1442 | or $self->throw_exception("No such relationship '$rel'"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1444 | 877 | my $ret = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1445 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1446 | 877 | ▶ | return $ret unless ((ref $rel_info->{cond}) eq 'HASH'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1448 | 876 | my $stripped_cond = $self->__strip_relcond ($rel_info->{cond}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1450 | 876 | my $registered_source_name = $self->source_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1451 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1452 | # this may be a partial schema or something else equally esoteric | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1453 | 876 | my $other_rsrc = $self->related_source($rel); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1455 | # Get all the relationships for that source that related to this source | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1456 | # whose foreign column set are our self columns on $rel and whose self | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1457 | # columns are our foreign columns on $rel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1458 | 876 | foreach my $other_rel ($other_rsrc->relationships) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1460 | # only consider stuff that points back to us | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1461 | # "us" here is tricky - if we are in a schema registration, we want | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1462 | # to use the source_names, otherwise we will use the actual classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1463 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1464 | # the schema may be partial | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1465 | 6775 | ▶ | my $roundtrip_rsrc = try { $other_rsrc->related_source($other_rel) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1466 | 6775 | ▶ | or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1468 | 6775 | ▶ | if ($registered_source_name) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1469 | 6761 | ▶ | next if $registered_source_name ne ($roundtrip_rsrc->source_name || '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$roundtrip_rsrc->source_name || ''
MC/DC0%0/1
$roundtrip_rsrc->source_name || ''
$roundtrip_rsrc->source_name
Truth table50%1/2
A
A= $roundtrip_rsrc->source_name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1470 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1471 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1472 | 14 | ▶ | next if $self->result_class ne $roundtrip_rsrc->result_class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1473 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1474 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1475 | 2306 | my $other_rel_info = $other_rsrc->relationship_info($other_rel); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1476 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1477 | # this can happen when we have a self-referential class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1478 | 2306 | ▶ | next if $other_rel_info eq $rel_info; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1479 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1480 | 2299 | ▶ | next unless ref $other_rel_info->{cond} eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1481 | 1894 | my $other_stripped_cond = $self->__strip_relcond($other_rel_info->{cond}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1482 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1483 | 1894 | ▶ | $ret->{$other_rel} = $other_rel_info if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->_compare_relationship_keys([keys %$stripped_cond], [values %$other_stripped_cond]) and $self->_compare_relationship_keys([values %$stripped_cond], [keys %$other_stripped_cond])
MC/DC50%1/2
$self->_compare_relationship_keys([keys %$stripped_cond], [values %$other_stripped_cond]) and $self->_compare_relationship_keys([values %$stripped_cond], [keys %$other_stripped_cond])
$self->_compare_relationship_keys([keys %$stripped_cond], [values %$other_stripped_cond])
$self->_compare_relationship_keys([values %$stripped_cond], [keys %$other_stripped_cond])
Truth table66%2/3
A and B
A= $self->_compare_relationship_keys([keys %$stripped_cond], [values %$other_stripped_cond])B= $self->_compare_relationship_keys([values %$stripped_cond], [keys %$other_stripped_cond])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1484 | $self->_compare_relationship_keys ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1485 | [ keys %$stripped_cond ], [ values %$other_stripped_cond ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1486 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1487 | and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1488 | $self->_compare_relationship_keys ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1489 | [ values %$stripped_cond ], [ keys %$other_stripped_cond ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1490 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1491 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1492 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1493 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1494 | 876 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1495 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1496 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1497 | # all this does is removes the foreign/self prefix from a condition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1498 | sub __strip_relcond { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1499 | +{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1500 | map | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1501 | 2770 | { map { /^ (?:foreign|self) \. (\w+) $/x } ($_, $_[1]{$_}) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1502 | 2770 | ▶ | keys %{$_[1]} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__strip_relcond: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1503 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1504 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1505 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1506 | sub compare_relationship_keys { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1507 | 0 | ▶ | carp 'compare_relationship_keys is a private method, stop calling it'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compare_relationship_keys: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1508 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1509 | 0 | $self->_compare_relationship_keys (@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1510 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1511 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1512 | # Returns true if both sets of keynames are the same, false otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1513 | sub _compare_relationship_keys { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1514 | # my ($self, $keys1, $keys2) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1515 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1516 | 3390 | join ("\x00", sort @{$_[1]}) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1517 | eq | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1518 | 3390 | ▶ | join ("\x00", sort @{$_[2]}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compare_relationship_keys: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1519 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1520 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1521 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1522 | # optionally takes either an arrayref of column names, or a hashref of already | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1523 | # retrieved colinfos | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1524 | # returns an arrayref of column names of the shortest unique constraint | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1525 | # (matching some of the input if any), giving preference to the PK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1526 | sub _identifying_column_set { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1527 | 600 | ▶ | my ($self, $cols) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_identifying_column_set: called CC=9 SCAR=22.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1529 | 600 | my %unique = $self->unique_constraints; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1530 | 600 | ▶ | my $colinfos = ref $cols eq 'HASH' ? $cols : $self->columns_info($cols||()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cols || ()
MC/DC0%0/2
$cols || ()
$cols
()
Truth table66%2/3
A || B
A= $colsB= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1531 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1532 | # always prefer the PK first, and then shortest constraints first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1533 | USET: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1534 | 600 | for my $set (delete $unique{primary}, sort { @$a <=> @$b } (values %unique) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1535 | 757 | ▶ | next unless $set && @$set; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$set and @$set
MC/DC0%0/2
$set and @$set
$set
@$set
Truth table33%1/3
A and B
A= $setB= @$set
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1537 | 757 | for (@$set) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1538 | 922 | ▶ | next USET unless ($colinfos->{$_} && !$colinfos->{$_}{is_nullable} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$colinfos->{$_} and not $colinfos->{$_}{"is_nullable"}
MC/DC100%2/2
$colinfos->{$_} and not $colinfos->{$_}{"is_nullable"}
$colinfos->{$_}
not $colinfos->{$_}{"is_nullable"}
Truth table100%3/3
A and not(B)
A= $colinfos->{$_}B= not $colinfos->{$_}{"is_nullable"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1539 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1540 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1541 | # copy so we can mangle it at will | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1542 | 562 | return [ @$set ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1543 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1544 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1545 | 38 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1546 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1547 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1548 | # Returns the {from} structure used to express JOIN conditions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1549 | sub _resolve_join { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1550 | 2288 | ▶ | my ($self, $join, $alias, $seen, $jpath, $parent_force_left) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_join: called CC=18 SCAR=29.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1551 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1552 | # we need a supplied one, because we do in-place modifications, no returns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1553 | 2288 | ▶ | $self->throw_exception ('You must supply a seen hashref as the 3rd argument to _resolve_join') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1554 | unless ref $seen eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1555 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1556 | 2288 | ▶ | $self->throw_exception ('You must supply a joinpath arrayref as the 4th argument to _resolve_join') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1557 | unless ref $jpath eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1558 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1559 | 2288 | $jpath = [@$jpath]; # copy | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1560 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1561 | 2288 | ▶ | if (not defined $join or not length $join) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition100%3/3
defined $join && length $join
MC/DC100%2/2
defined $join && length $join
defined $join
length $join
Truth table100%3/3
A && B
A= defined $joinB= length $join
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1562 | 408 | return (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1563 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1564 | elsif (ref $join eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1565 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1566 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1567 | 508 | $self->_resolve_join($_, $alias, $seen, $jpath, $parent_force_left); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1568 | } @$join; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1570 | elsif (ref $join eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1571 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1572 | 247 | my @ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1573 | 247 | for my $rel (keys %$join) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1574 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1575 | 244 | ▶ | my $rel_info = $self->relationship_info($rel) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1576 | or $self->throw_exception("No such relationship '$rel' on " . $self->source_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1577 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1578 | 244 | my $force_left = $parent_force_left; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1579 | 244 | ▶ | $force_left ||= lc($rel_info->{attrs}{join_type}||'') eq 'left'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%5/5
$force_left ||= lc($rel_info->{"attrs"}{"join_type"} || "") eq "left"
$rel_info->{'attrs'}{'join_type'} || ''
MC/DC100%2/2
$force_left ||= lc($rel_info->{"attrs"}{"join_type"} || "") eq "left"
$force_left
$rel_info->{'attrs'}{'join_type'}
Truth table100%3/3
A ||= B
A= $force_leftB= $rel_info->{'attrs'}{'join_type'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1580 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1581 | # the actual seen value will be incremented by the recursion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1582 | my $as = $self->storage->relname_to_table_alias( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1583 | 244 | ▶ | $rel, ($seen->{$rel} && $seen->{$rel} + 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$seen->{$rel} && $seen->{$rel} + 1
MC/DC50%1/2
$seen->{$rel} && $seen->{$rel} + 1
$seen->{$rel}
$seen->{$rel} + 1
Truth table66%2/3
A && B
A= $seen->{$rel}B= $seen->{$rel} + 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1584 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1585 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1586 | push @ret, ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1587 | $self->_resolve_join($rel, $alias, $seen, [@$jpath], $force_left), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1588 | $self->related_source($rel)->_resolve_join( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1589 | 244 | $join->{$rel}, $as, $seen, [@$jpath, { $rel => $as }], $force_left | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1590 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1591 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1592 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1593 | 247 | return @ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1594 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1595 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1596 | elsif (ref $join) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1597 | 0 | $self->throw_exception("No idea how to resolve join reftype ".ref $join); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1598 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1599 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1600 | 1125 | my $count = ++$seen->{$join}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1601 | 1125 | ▶ | my $as = $self->storage->relname_to_table_alias( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$count > 1 && $count
MC/DC50%1/2
$count > 1 && $count
$count > 1
$count
Truth table66%2/3
A && B
A= $count > 1B= $count
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1602 | $join, ($count > 1 && $count) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1603 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1604 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1605 | 1125 | ▶ | my $rel_info = $self->relationship_info($join) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1606 | or $self->throw_exception("No such relationship $join on " . $self->source_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1607 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1608 | 1125 | my $rel_src = $self->related_source($join); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1609 | return [ { $as => $rel_src->from, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1610 | -rsrc => $rel_src, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1611 | -join_type => $parent_force_left | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1612 | ? 'left' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1613 | : $rel_info->{attrs}{join_type} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1614 | , | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1615 | -join_path => [@$jpath, { $join => $as } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1616 | -is_single => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1617 | (! $rel_info->{attrs}{accessor}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1618 | or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1619 | 1972 | ▶ | first { $rel_info->{attrs}{accessor} eq $_ } (qw/single filter/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1620 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1621 | -alias => $as, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1622 | -relation_chain_depth => ( $seen->{-relation_chain_depth} || 0 ) + 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1623 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1624 | 1125 | ▶ | scalar $self->_resolve_condition($rel_info->{cond}, $as, $alias, $join) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
!$rel_info->{'attrs'}{'accessor'} || &first(sub {
$rel_info->{'attrs'}{'accessor'} eq $_;
}
, 'single', 'filter')
$seen->{'-relation_chain_depth'} || 0
MC/DC50%1/2
!$rel_info->{'attrs'}{'accessor'} || &first(sub {
$rel_info->{'attrs'}{'accessor'} eq $_;
}
, 'single', 'filter')
!$rel_info->{'attrs'}{'accessor'}
&first(sub {
$rel_info->{'attrs'}{'accessor'} eq $_;
}
, 'single', 'filter')
MC/DC100%1/1
$seen->{'-relation_chain_depth'} || 0
$seen->{'-relation_chain_depth'}
Truth table66%2/3
not(A) || B
A= !$rel_info->{'attrs'}{'accessor'}B= &first(sub {
$rel_info->{'attrs'}{'accessor'} eq $_;
}
, 'single', 'filter')
Truth table100%2/2
A
A= $seen->{'-relation_chain_depth'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1625 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1626 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1627 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1628 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1629 | sub pk_depends_on { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1630 | 0 | ▶ | carp 'pk_depends_on is a private method, stop calling it'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pk_depends_on: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1631 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1632 | 0 | $self->_pk_depends_on (@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1633 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1634 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1635 | # Determines whether a relation is dependent on an object from this source | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1636 | # having already been inserted. Takes the name of the relationship and a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1637 | # hashref of columns of the related object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1638 | sub _pk_depends_on { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1639 | 649 | ▶ | my ($self, $rel_name, $rel_data) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pk_depends_on: called CC=7 SCAR=20.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1640 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1641 | 649 | my $relinfo = $self->relationship_info($rel_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1642 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1643 | # don't assume things if the relationship direction is specified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1644 | return $relinfo->{attrs}{is_foreign_key_constraint} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1645 | 649 | ▶ | if exists ($relinfo->{attrs}{is_foreign_key_constraint}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1646 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1647 | 172 | my $cond = $relinfo->{cond}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1648 | 172 | ▶ | return 0 unless ref($cond) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1649 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1650 | # map { foreign.foo => 'self.bar' } to { bar => 'foo' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1651 | 172 | my $keyhash = { map { my $x = $_; $x =~ s/.*\.//; $x; } reverse %$cond }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1652 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1653 | # assume anything that references our PK probably is dependent on us | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1654 | # rather than vice versa, unless the far side is (a) defined or (b) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1655 | # auto-increment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1656 | 172 | my $rel_source = $self->related_source($rel_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1657 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1658 | 172 | foreach my $p ($self->primary_columns) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1659 | 172 | ▶ | if (exists $keyhash->{$p}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1660 | 172 | ▶ | unless (defined($rel_data->{$keyhash->{$p}}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $$rel_data{$keyhash->{$p}} or $rel_source->column_info($keyhash->{$p})->{"is_auto_increment"}
MC/DC0%0/2
defined $$rel_data{$keyhash->{$p}} or $rel_source->column_info($keyhash->{$p})->{"is_auto_increment"}
defined $$rel_data{$keyhash->{$p}}
$rel_source->column_info($keyhash->{$p})->{"is_auto_increment"}
Truth table33%1/3
A or B
A= defined $$rel_data{$keyhash->{$p}}B= $rel_source->column_info($keyhash->{$p})->{"is_auto_increment"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1661 | || $rel_source->column_info($keyhash->{$p}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1662 | ->{is_auto_increment}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1663 | 172 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1664 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1665 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1666 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1667 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1668 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1669 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1670 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1671 | sub resolve_condition { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1672 | 0 | ▶ | carp 'resolve_condition is a private method, stop calling it'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolve_condition: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1673 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1674 | 0 | $self->_resolve_condition (@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1675 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1676 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1677 | 308 | our $UNRESOLVABLE_CONDITION = \ '1 = 0'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1678 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1679 | # Resolves the passed condition to a concrete query fragment and a flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1680 | # indicating whether this is a cross-table condition. Also an optional | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1681 | # list of non-trivial values (normally conditions) returned as a part | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1682 | # of a joinfree condition hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1683 | sub _resolve_condition { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1684 | 5725 | ▶ | my ($self, $cond, $as, $for, $rel_name) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_condition: called CC=41 SCAR=38.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1685 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1686 | 5725 | my $obj_rel = defined blessed $for; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1687 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1688 | 5725 | ▶ | if (ref $cond eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1689 | 206 | ▶ | my $relalias = $obj_rel ? 'me' : $as; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1690 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1691 | 206 | ▶ | my ($crosstable_cond, $joinfree_cond) = $cond->({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
$rel_name || ($obj_rel ? $as : $for)
MC/DC0%0/2
$rel_name || ($obj_rel ? $as : $for)
$rel_name
($obj_rel ? $as : $for)
Truth table33%1/3
A || B
A= $rel_nameB= ($obj_rel ? $as : $for)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1692 | self_alias => $obj_rel ? $as : $for, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1693 | foreign_alias => $relalias, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1694 | self_resultsource => $self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1695 | foreign_relname => $rel_name || ($obj_rel ? $as : $for), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1696 | self_rowobj => $obj_rel ? $for : undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1697 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1698 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1699 | 206 | my $cond_cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1700 | 206 | ▶ | if ($joinfree_cond) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1701 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1702 | # FIXME sanity check until things stabilize, remove at some point | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1703 | 15 | ▶ | $self->throw_exception ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1704 | "A join-free condition returned for relationship '$rel_name' without a row-object to chain from" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1705 | ) unless $obj_rel; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1706 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1707 | # FIXME another sanity check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1708 | 15 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $joinfree_cond ne "HASH" or &first(sub {
not $_ =~ /^\Q$relalias.\E.+/;
}
, keys %$joinfree_cond)
MC/DC0%0/2
ref $joinfree_cond ne "HASH" or &first(sub {
not $_ =~ /^\Q$relalias.\E.+/;
}
, keys %$joinfree_cond)
ref $joinfree_cond ne "HASH"
&first(sub {
not $_ =~ /^\Q$relalias.\E.+/;
}
, keys %$joinfree_cond)
Truth table33%1/3
A or B
A= ref $joinfree_cond ne "HASH"B= &first(sub {
not $_ =~ /^\Q$relalias.\E.+/;
}
, keys %$joinfree_cond)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1709 | ref $joinfree_cond ne 'HASH' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1710 | or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1711 | 29 | ▶ | first { $_ !~ /^\Q$relalias.\E.+/ } keys %$joinfree_cond | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1712 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1713 | 0 | $self->throw_exception ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1714 | "The join-free condition returned for relationship '$rel_name' must be a hash " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1715 | .'reference with all keys being valid columns on the related result source' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1716 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1717 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1718 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1719 | # normalize | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1720 | 15 | for (values %$joinfree_cond) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1721 | $_ = $_->{'='} if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1722 | ref $_ eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1723 | and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1724 | keys %$_ == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1725 | and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1726 | 29 | ▶ | exists $_->{'='} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
ref $_ eq "HASH" and keys %$_ == 1 and exists $_->{"="}
ref $_ eq "HASH" and keys %$_ == 1
MC/DC0%0/3
ref $_ eq "HASH" and keys %$_ == 1 and exists $_->{"="}
ref $_ eq "HASH"
keys %$_ == 1
exists $_->{"="}
Truth table75%3/4
A and B and C
A= ref $_ eq "HASH"B= keys %$_ == 1C= exists $_->{"="}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1727 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1728 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1729 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1730 | # see which parts of the joinfree cond are conditionals | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1731 | 15 | my $relcol_list = { map { $_ => 1 } $self->related_source($rel_name)->columns }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1732 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1733 | 15 | for my $c (keys %$joinfree_cond) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1734 | 29 | my ($colname) = $c =~ /^ (?: \Q$relalias.\E )? (.+)/x; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1735 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1736 | 29 | ▶ | unless ($relcol_list->{$colname}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1737 | 0 | push @$cond_cols, $colname; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1738 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1739 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1740 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1741 | 29 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
ref $joinfree_cond->{$c} and ref $joinfree_cond->{$c} ne "SCALAR" and ref $joinfree_cond->{$c} ne "REF"
ref $joinfree_cond->{$c} and ref $joinfree_cond->{$c} ne "SCALAR"
MC/DC33%1/3
ref $joinfree_cond->{$c} and ref $joinfree_cond->{$c} ne "SCALAR" and ref $joinfree_cond->{$c} ne "REF"
ref $joinfree_cond->{$c}
ref $joinfree_cond->{$c} ne "SCALAR"
ref $joinfree_cond->{$c} ne "REF"
Truth table50%2/4
A and B and C
A= ref $joinfree_cond->{$c}B= ref $joinfree_cond->{$c} ne "SCALAR"C= ref $joinfree_cond->{$c} ne "REF"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1742 | ref $joinfree_cond->{$c} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1743 | and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1744 | ref $joinfree_cond->{$c} ne 'SCALAR' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1745 | and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1746 | ref $joinfree_cond->{$c} ne 'REF' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1747 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1748 | 11 | push @$cond_cols, $colname; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1749 | 11 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1750 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1751 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1752 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1753 | 15 | ▶ | return wantarray ? ($joinfree_cond, 0, $cond_cols) : $joinfree_cond; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1754 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1755 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1756 | 191 | ▶ | return wantarray ? ($crosstable_cond, 1) : $crosstable_cond; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1757 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1758 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1759 | elsif (ref $cond eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1760 | 5504 | my %ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1761 | 5504 | foreach my $k (keys %{$cond}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1762 | 5591 | my $v = $cond->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1763 | # XXX should probably check these are valid columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1764 | 5591 | ▶ | $k =~ s/^foreign\.// || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1765 | $self->throw_exception("Invalid rel cond key ${k}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1766 | 5591 | ▶ | $v =~ s/^self\.// || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1767 | $self->throw_exception("Invalid rel cond val ${v}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1768 | 5591 | ▶ | if (ref $for) { # Object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1769 | #warn "$self $k $for $v"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1770 | 3879 | ▶ | unless ($for->has_column_loaded($v)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1771 | 70 | ▶ | if ($for->in_storage) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1772 | 2 | $self->throw_exception(sprintf | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1773 | "Unable to resolve relationship '%s' from object %s: column '%s' not " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1774 | . 'loaded from storage (or not passed to new() prior to insert()). You ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1775 | . 'probably need to call ->discard_changes to get the server-side defaults ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1776 | . 'from the database.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1777 | $as, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1778 | $for, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1779 | $v, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1780 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1781 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1782 | 68 | return $UNRESOLVABLE_CONDITION; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1783 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1784 | 3809 | $ret{$k} = $for->get_column($v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1785 | #$ret{$k} = $for->get_column($v) if $for->has_column_loaded($v); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1786 | #warn %ret; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1787 | } elsif (!defined $for) { # undef, i.e. "no object" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1788 | 0 | $ret{$k} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1789 | } elsif (ref $as eq 'HASH') { # reverse hashref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1790 | 2 | $ret{$v} = $as->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1791 | } elsif (ref $as) { # reverse object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1792 | 620 | $ret{$v} = $as->get_column($k); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1793 | } elsif (!defined $as) { # undef, i.e. "no reverse object" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1794 | 1 | $ret{$v} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1795 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1796 | 1089 | $ret{"${as}.${k}"} = { -ident => "${for}.${v}" }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1797 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1798 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1799 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1800 | return wantarray | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1801 | 5434 | ▶ | ? ( \%ret, ($obj_rel || !defined $as || ref $as) ? 0 : 1 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%6/6
$obj_rel or not defined $as or ref $as
$obj_rel or not defined $as
MC/DC100%3/3
$obj_rel or not defined $as or ref $as
$obj_rel
not defined $as
ref $as
Truth table100%4/4
A or not(B) or C
A= $obj_relB= not defined $asC= ref $as
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1802 | : \%ret | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1803 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1804 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1805 | elsif (ref $cond eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1806 | 15 | my (@ret, $crosstable); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1807 | 15 | for (@$cond) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1808 | 30 | my ($cond, $crosstab) = $self->_resolve_condition($_, $as, $for, $rel_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1809 | 30 | push @ret, $cond; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1810 | 30 | ▶ | $crosstable ||= $crosstab; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$crosstable ||= $crosstab
MC/DC100%2/2
$crosstable ||= $crosstab
$crosstable
$crosstab
Truth table100%3/3
A ||= B
A= $crosstableB= $crosstab
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1811 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1812 | 15 | ▶ | return wantarray ? (\@ret, $crosstable) : \@ret; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1813 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1814 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1815 | 0 | $self->throw_exception ("Can't handle condition $cond for relationship '$rel_name' yet :("); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1816 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1817 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1818 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1819 | =head2 related_source | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1820 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1821 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1822 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1823 | =item Arguments: $rel_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1824 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1825 | =item Return Value: $source | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1826 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1827 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1828 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1829 | Returns the result source object for the given relationship. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1830 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1831 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1832 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1833 | sub related_source { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1834 | 13638 | ▶ | my ($self, $rel) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
related_source: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1835 | 13638 | ▶ | if( !$self->has_relationship( $rel ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1836 | 0 | $self->throw_exception("No such relationship '$rel' on " . $self->source_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1837 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1838 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1839 | # if we are not registered with a schema - just use the prototype | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1840 | # however if we do have a schema - ask for the source by name (and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1841 | # throw in the process if all fails) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1842 | 13638 | ▶ | if (my $schema = try { $self->schema }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1843 | 13619 | $schema->source($self->relationship_info($rel)->{source}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1844 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1845 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1846 | 19 | my $class = $self->relationship_info($rel)->{class}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1847 | 19 | $self->ensure_class_loaded($class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1848 | 19 | $class->result_source_instance; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1849 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1850 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1851 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1852 | =head2 related_class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1853 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1854 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1855 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1856 | =item Arguments: $rel_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1857 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1858 | =item Return Value: $classname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1859 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1860 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1861 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1862 | Returns the class name for objects in the given relationship. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1863 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1864 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1865 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1866 | sub related_class { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1867 | 0 | ▶ | my ($self, $rel) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
related_class: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1868 | 0 | ▶ | if( !$self->has_relationship( $rel ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1869 | 0 | $self->throw_exception("No such relationship '$rel' on " . $self->source_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1870 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1871 | 0 | return $self->schema->class($self->relationship_info($rel)->{source}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1872 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1873 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1874 | =head2 handle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1875 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1876 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1877 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1878 | =item Arguments: none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1879 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1880 | =item Return Value: L<$source_handle|DBIx::Class::ResultSourceHandle> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1881 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1882 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1883 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1884 | Obtain a new L<result source handle instance|DBIx::Class::ResultSourceHandle> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1885 | for this source. Used as a serializable pointer to this resultsource, as it is not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1886 | easy (nor advisable) to serialize CODErefs which may very well be present in e.g. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1887 | relationship definitions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1888 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1889 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1890 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1891 | sub handle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1892 | return DBIx::Class::ResultSourceHandle->new({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1893 | source_moniker => $_[0]->source_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1894 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1895 | # so that a detached thaw can be re-frozen | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1896 | $_[0]->{_detached_thaw} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1897 | 206 | ▶ | ? ( _detached_source => $_[0] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1898 | : ( schema => $_[0]->schema ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1899 | , | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1900 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1901 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1902 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1903 | 308 | my $global_phase_destroy; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1904 | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1905 | 113499 | ▶ | return if $global_phase_destroy ||= in_global_destruction; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=10 SCAR=23.7
Branch: 1 branch
Condition33%1/3
$global_phase_destroy ||= &in_global_destruction()
MC/DC0%0/2
$global_phase_destroy ||= &in_global_destruction()
$global_phase_destroy
&in_global_destruction()
Truth table33%1/3
A ||= B
A= $global_phase_destroyB= &in_global_destruction()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1906 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1907 | ###### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1908 | # !!! ACHTUNG !!!! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1909 | ###### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1910 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1911 | # Under no circumstances shall $_[0] be stored anywhere else (like copied to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1912 | # a lexical variable, or shifted, or anything else). Doing so will mess up | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1913 | # the refcount of this particular result source, and will allow the $schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1914 | # we are trying to save to reattach back to the source we are destroying. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1915 | # The relevant code checking refcounts is in ::Schema::DESTROY() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1916 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1917 | # if we are not a schema instance holder - we don't matter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1918 | return if( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1919 | ! ref $_[0]->{schema} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1920 | or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1921 | isweak $_[0]->{schema} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1922 | 113499 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not ref $_[0]{"schema"} or builtin::is_weak($_[0]{"schema"})
MC/DC100%2/2
not ref $_[0]{"schema"} or builtin::is_weak($_[0]{"schema"})
not ref $_[0]{"schema"}
builtin::is_weak($_[0]{"schema"})
Truth table100%3/3
not(A) or B
A= not ref $_[0]{"schema"}B= builtin::is_weak($_[0]{"schema"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1923 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1924 | # weaken our schema hold forcing the schema to find somewhere else to live | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1925 | # during global destruction (if we have not yet bailed out) this will throw | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1926 | # which will serve as a signal to not try doing anything else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1927 | # however beware - on older perls the exception seems randomly untrappable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1928 | # due to some weird race condition during thread joining :((( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1929 | 17251 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1930 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1931 | 17251 | weaken $_[0]->{schema}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1932 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1933 | # if schema is still there reintroduce ourselves with strong refs back to us | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1934 | 17251 | ▶ | if ($_[0]->{schema}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1935 | 17240 | my $srcregs = $_[0]->{schema}->source_registrations; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1936 | 17240 | for (keys %$srcregs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1937 | 793136 | ▶ | next unless $srcregs->{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1938 | 793136 | ▶ | $srcregs->{$_} = $_[0] if $srcregs->{$_} == $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1939 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1940 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1941 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1942 | 17251 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1943 | 17251 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1944 | 0 | $global_phase_destroy = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1945 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1946 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1947 | 17251 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1948 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1949 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1950 | 204 | ▶ | sub STORABLE_freeze { Storable::nfreeze($_[0]->handle) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
STORABLE_freeze: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1951 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1952 | sub STORABLE_thaw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1953 | 204 | ▶ | my ($self, $cloning, $ice) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
STORABLE_thaw: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1954 | 204 | %$self = %{ (Storable::thaw($ice))->resolve }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1955 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1956 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1957 | =head2 throw_exception | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1958 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1959 | See L<DBIx::Class::Schema/"throw_exception">. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1960 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1961 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1962 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1963 | sub throw_exception { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1964 | 1951 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
throw_exception: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1965 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1966 | $self->{schema} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1967 | 1951 | ▶ | ? $self->{schema}->throw_exception(@_) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1968 | : DBIx::Class::Exception->throw(@_) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1969 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1970 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1971 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1972 | =head2 source_info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1973 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1974 | Stores a hashref of per-source metadata. No specific key names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1975 | have yet been standardized, the examples below are purely hypothetical | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1976 | and don't actually accomplish anything on their own: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1977 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1978 | __PACKAGE__->source_info({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1979 | "_tablespace" => 'fast_disk_array_3', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1980 | "_engine" => 'InnoDB', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1981 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1982 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1983 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1984 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1985 | $class->new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1986 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1987 | $class->new({attribute_name => value}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1988 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1989 | Creates a new ResultSource object. Not normally called directly by end users. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1990 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1991 | =head2 column_info_from_storage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1992 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1993 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1994 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1995 | =item Arguments: 1/0 (default: 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1996 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1997 | =item Return Value: 1/0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1998 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1999 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2000 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2001 | __PACKAGE__->column_info_from_storage(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2002 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2003 | Enables the on-demand automatic loading of the above column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2004 | metadata from storage as necessary. This is *deprecated*, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2005 | should not be used. It will be removed before 1.0. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2006 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2007 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2008 | =head1 AUTHOR AND CONTRIBUTORS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2009 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2010 | See L<AUTHOR|DBIx::Class/AUTHOR> and L<CONTRIBUTORS|DBIx::Class/CONTRIBUTORS> in DBIx::Class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2011 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2012 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2013 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2014 | You may distribute this code under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2015 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2016 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2017 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2018 | 308 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||