| 1 | package CatalystX::CRUD::ModelAdapter::DBIC; | ||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use base qw( | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | CatalystX::CRUD::ModelAdapter | ||||||||||||||||||||||||||||||||||
| 6 | CatalystX::CRUD::Model::Utils | ||||||||||||||||||||||||||||||||||
| 7 | 3 | ); | |||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use MRO::Compat; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use mro 'c3'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Scalar::Util qw( weaken ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Data::Dump qw( dump ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Sort::SQL; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | 3 | __PACKAGE__->mk_ro_accessors(qw( treat_like_int )); | |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | 3 | our $VERSION = '0.15'; | |||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | CatalystX::CRUD::ModelAdapter::DBIC - CRUD for Catalyst::Model::DBIC::Schema | ||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | # create an adapter class (NOTE not in ::Model namespace) | ||||||||||||||||||||||||||||||||||
| 26 | package MyApp::MyDBICAdapter; | ||||||||||||||||||||||||||||||||||
| 27 | use strict; | ||||||||||||||||||||||||||||||||||
| 28 | use base qw( CatalystX::CRUD::ModelAdapter::DBIC ); | ||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||
| 30 | 1; | ||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | # your main DBIC::Schema model | ||||||||||||||||||||||||||||||||||
| 33 | package MyApp::Model::MyDBIC; | ||||||||||||||||||||||||||||||||||
| 34 | use strict; | ||||||||||||||||||||||||||||||||||
| 35 | use base qw( Catalyst::Model::DBIC::Schema ); | ||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | 1; | ||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | CatalystX::CRUD::ModelAdapter::DBIC implements the CatalystX::CRUD::ModelAdapter | ||||||||||||||||||||||||||||||||||
| 42 | API for DBIx::Class. | ||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||
| 44 | =head1 METHODS | ||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | =head2 new( I<opts> ) | ||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||
| 48 | Overrides base method to initialize treats_like_int, ne_sign and | ||||||||||||||||||||||||||||||||||
| 49 | use_ilike values. | ||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||
| 51 | =cut | ||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | # TODO others? | ||||||||||||||||||||||||||||||||||
| 54 | 3 | my %is_iliker = ( | |||||||||||||||||||||||||||||||||
| 55 | Pg => 1, | ||||||||||||||||||||||||||||||||||
| 56 | PostgreSQL => 1, | ||||||||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 60 | 0 | my $self = shift->next::method(@_); | |||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||
| 62 | # what kind of db driver are we using. | ||||||||||||||||||||||||||||||||||
| 63 | # makes a difference in make_sql_query(). | ||||||||||||||||||||||||||||||||||
| 64 | 0 | my $db_type | |||||||||||||||||||||||||||||||||
| 65 | = $self->app_class->model( $self->model_name )->storage->sqlt_type; | ||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | #warn "DBIC driver: " . $db_type; | ||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | 0 | $self->use_ilike( exists $is_iliker{$db_type} ); | |||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | # SQL for not equal | ||||||||||||||||||||||||||||||||||
| 72 | 0 | $self->ne_sign('!='); | |||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||
| 74 | # cache the treat_like_int hash | ||||||||||||||||||||||||||||||||||
| 75 | 0 | $self->_treat_like_int; | |||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | #warn dump $self; | ||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||
| 79 | 0 | return $self; | |||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub _treat_like_int { | ||||||||||||||||||||||||||||||||
|
Subroutine
_treat_like_int: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||
| 83 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 84 | 0 | my $treat = {}; | |||||||||||||||||||||||||||||||||
| 85 | 0 | my $moniker = $self->_get_moniker; | |||||||||||||||||||||||||||||||||
| 86 | 0 | my $rs_class = $self->app_class->model( $self->model_name ) | |||||||||||||||||||||||||||||||||
| 87 | ->composed_schema->class($moniker); | ||||||||||||||||||||||||||||||||||
| 88 | 0 | for my $col ( $rs_class->columns ) { | |||||||||||||||||||||||||||||||||
| 89 | 0 | my $info = $rs_class->column_info($col); | |||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||
| 91 | #warn "$col : " . dump($info); | ||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ( keys %$info ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if ( $info->{data_type} | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$info->{"data_type"} and $info->{"data_type"} =~ /(boolean|date|int)/
MC/DC0%0/2
$info->{"data_type"} and $info->{"data_type"} =~ /(boolean|date|int)/
$info->{"data_type"}
$info->{"data_type"} =~ /(boolean|date|int)/
Truth table0%0/3
A and B
A= $info->{"data_type"}B= $info->{"data_type"} =~ /(boolean|date|int)/
| |||||||||||||||||||||||||||||||||||
| 95 | and $info->{data_type} =~ m/(boolean|date|int)/ ) | ||||||||||||||||||||||||||||||||||
| 96 | { | ||||||||||||||||||||||||||||||||||
| 97 | 0 | $treat->{$col} = 1; | |||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||
| 103 | 0 | $self->{treat_like_int} = $treat; | |||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | =head2 new_object( I<controller>, I<context>, I<moniker> ) | ||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||
| 108 | Implement required method. Returns empty new_result() object | ||||||||||||||||||||||||||||||||||
| 109 | from resultset() of I<moniker>. | ||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||
| 111 | =cut | ||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | sub new_object { | ||||||||||||||||||||||||||||||||
|
Subroutine
new_object: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 114 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 115 | 0 | my $controller = shift; | |||||||||||||||||||||||||||||||||
| 116 | 0 | my $c = shift; | |||||||||||||||||||||||||||||||||
| 117 | 0 | my $moniker = $self->_get_moniker($c); | |||||||||||||||||||||||||||||||||
| 118 | 0 | return $c->model( $self->model_name )->resultset($moniker) | |||||||||||||||||||||||||||||||||
| 119 | ->new_result( {} ); | ||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||
| 122 | =head2 fetch( I<controller>, I<context>, I<moniker> [, I<args>] ) | ||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||
| 124 | Implements required method. Returns new_object() matching I<args>. | ||||||||||||||||||||||||||||||||||
| 125 | I<args> is passed to the find() method of the resultset() for I<moniker>. | ||||||||||||||||||||||||||||||||||
| 126 | If I<args> is not passed, fetch() acts the same as calling new_object(). | ||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||
| 128 | =cut | ||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | sub fetch { | ||||||||||||||||||||||||||||||||
|
Subroutine
fetch: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 131 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 132 | 0 | my $controller = shift; | |||||||||||||||||||||||||||||||||
| 133 | 0 | my $c = shift; | |||||||||||||||||||||||||||||||||
| 134 | 0 | my $moniker = $self->_get_moniker($c); | |||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 136 | 0 | my $dbic_obj; | |||||||||||||||||||||||||||||||||
| 137 | 0 | eval { | |||||||||||||||||||||||||||||||||
| 138 | 0 | $dbic_obj | |||||||||||||||||||||||||||||||||
| 139 | = $c->model( $self->model_name )->resultset($moniker) | ||||||||||||||||||||||||||||||||||
| 140 | ->find( {@_} ); | ||||||||||||||||||||||||||||||||||
| 141 | }; | ||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if ( $@ or !$dbic_obj ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$@ or not $dbic_obj
MC/DC0%0/2
$@ or not $dbic_obj
$@
not $dbic_obj
Truth table0%0/3
A or not(B)
A= $@B= not $dbic_obj
| |||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | my $err = defined($dbic_obj) ? $dbic_obj->error : $@; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 144 | return | ||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if $self->throw_error( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 146 | "can't create new $moniker object: $err"); | ||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||
| 149 | 0 | return $dbic_obj; | |||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||
| 151 | else { | ||||||||||||||||||||||||||||||||||
| 152 | 0 | return $self->new_object( $controller, $c ); | |||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||
| 156 | =head2 search( I<controller>, I<context>, I<args> ) | ||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||
| 158 | Implements required method. Returns array or array ref, based | ||||||||||||||||||||||||||||||||||
| 159 | on calling context, for a search() in resultset() for I<args>. | ||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||
| 161 | =cut | ||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | sub search { | ||||||||||||||||||||||||||||||||
|
Subroutine
search: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 164 | 0 | my ( $self, $controller, $c, @arg ) = @_; | |||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | my $query = shift(@arg) || $self->make_query( $controller, $c ); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
shift @arg || $self->make_query($controller, $c)
MC/DC0%0/2
shift @arg || $self->make_query($controller, $c)
shift @arg
$self->make_query($controller, $c)
Truth table0%0/3
A || B
A= shift @argB= $self->make_query($controller, $c)
| |||||||||||||||||||||||||||||||||||
| 166 | my @rs | ||||||||||||||||||||||||||||||||||
| 167 | = $c->model( $self->model_name ) | ||||||||||||||||||||||||||||||||||
| 168 | ->resultset( $self->_get_moniker($c) ) | ||||||||||||||||||||||||||||||||||
| 169 | 0 | ->search( $query->{WHERE}, $query->{OPTS} ); | |||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | return wantarray ? @rs : \@rs; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | sub _get_moniker { | ||||||||||||||||||||||||||||||||
|
Subroutine
_get_moniker: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||
| 174 | 0 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||||||||
| 175 | 0 | my $moniker; | |||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | if ( defined $c ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 177 | $moniker = $c->stash->{dbic_schema} | ||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | || $self->model_meta->{dbic_schema}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$c->stash->{'dbic_schema'} || $self->model_meta->{'dbic_schema'}
MC/DC0%0/2
$c->stash->{'dbic_schema'} || $self->model_meta->{'dbic_schema'}
$c->stash->{'dbic_schema'}
$self->model_meta->{'dbic_schema'}
Truth table0%0/3
A || B
A= $c->stash->{'dbic_schema'}B= $self->model_meta->{'dbic_schema'}
| |||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||
| 180 | else { | ||||||||||||||||||||||||||||||||||
| 181 | 0 | $moniker = $self->model_meta->{dbic_schema}; | |||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | unless ($moniker) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 184 | 0 | $self->throw_error( | |||||||||||||||||||||||||||||||||
| 185 | "must define a dbic_schema in model_meta config for each CRUD controller" | ||||||||||||||||||||||||||||||||||
| 186 | ); | ||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||
| 188 | 0 | return $moniker; | |||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||
| 191 | =head2 iterator( I<controller>, I<context>, I<args> ) | ||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||
| 193 | Implements required method. Returns iterator | ||||||||||||||||||||||||||||||||||
| 194 | for a search() in resultset() for I<args>. | ||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||
| 196 | =cut | ||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | sub iterator { | ||||||||||||||||||||||||||||||||
|
Subroutine
iterator: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 199 | 0 | my ( $self, $controller, $c, @arg ) = @_; | |||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | my $query = shift(@arg) || $self->make_query( $controller, $c ); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
shift @arg || $self->make_query($controller, $c)
MC/DC0%0/2
shift @arg || $self->make_query($controller, $c)
shift @arg
$self->make_query($controller, $c)
Truth table0%0/3
A || B
A= shift @argB= $self->make_query($controller, $c)
| |||||||||||||||||||||||||||||||||||
| 201 | my $rs | ||||||||||||||||||||||||||||||||||
| 202 | = $c->model( $self->model_name ) | ||||||||||||||||||||||||||||||||||
| 203 | ->resultset( $self->_get_moniker($c) ) | ||||||||||||||||||||||||||||||||||
| 204 | 0 | ->search( $query->{WHERE}, $query->{OPTS} ); | |||||||||||||||||||||||||||||||||
| 205 | 0 | return $rs; | |||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||
| 208 | =head2 count( I<controller>, I<context>, I<args> ) | ||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||
| 210 | Implements required method. Returns count() in resultset() for I<args>. | ||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||
| 212 | =cut | ||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | sub count { | ||||||||||||||||||||||||||||||||
|
Subroutine
count: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 215 | 0 | my ( $self, $controller, $c, @arg ) = @_; | |||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | my $query = shift(@arg) || $self->make_query( $controller, $c ); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
shift @arg || $self->make_query($controller, $c)
MC/DC0%0/2
shift @arg || $self->make_query($controller, $c)
shift @arg
$self->make_query($controller, $c)
Truth table0%0/3
A || B
A= shift @argB= $self->make_query($controller, $c)
| |||||||||||||||||||||||||||||||||||
| 217 | return $c->model( $self->model_name ) | ||||||||||||||||||||||||||||||||||
| 218 | ->resultset( $self->_get_moniker($c) ) | ||||||||||||||||||||||||||||||||||
| 219 | 0 | ->count( $query->{WHERE}, $query->{OPTS} ); | |||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||
| 222 | =head2 make_query( I<controller>, I<context> [, I<field_names> ] ) | ||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||
| 224 | Returns an array ref of query data based on request params in I<context>, | ||||||||||||||||||||||||||||||||||
| 225 | using param names that match I<field_names>. | ||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||
| 227 | =cut | ||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | sub make_query { | ||||||||||||||||||||||||||||||||
|
Subroutine
make_query: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 230 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 231 | 0 | my $controller = shift; | |||||||||||||||||||||||||||||||||
| 232 | 0 | my $c = shift; | |||||||||||||||||||||||||||||||||
| 233 | my $field_names | ||||||||||||||||||||||||||||||||||
| 234 | = shift | ||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | || $c->req->params->{'cxc-query-fields'} | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
shift() || $c->req->params->{'cxc-query-fields'} || $self->_get_field_names($controller, $c)
shift() or $c->req->params->{"cxc-query-fields"}
MC/DC0%0/3
shift() || $c->req->params->{'cxc-query-fields'} || $self->_get_field_names($controller, $c)
shift()
$c->req->params->{"cxc-query-fields"}
$self->_get_field_names($controller, $c)
Truth table0%0/4
A or B || C
A= shift()B= $c->req->params->{"cxc-query-fields"}C= $self->_get_field_names($controller, $c)
| |||||||||||||||||||||||||||||||||||
| 236 | || $self->_get_field_names( $controller, $c ); | ||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | my $query = $self->make_sql_query( $controller, $c, $field_names ) || {}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->make_sql_query($controller, $c, $field_names) || {}
MC/DC0%0/1
$self->make_sql_query($controller, $c, $field_names) || {}
$self->make_sql_query($controller, $c, $field_names)
Truth table0%0/2
A
A= $self->make_sql_query($controller, $c, $field_names)
| |||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||
| 240 | # WHERE | ||||||||||||||||||||||||||||||||||
| 241 | 0 | $query->{WHERE} = { @{ $query->{query} } }; | |||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||
| 243 | 0 | my %opts; | |||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||
| 245 | # PREFETCH, etc. | ||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | if ( $controller->model_meta->{resultset_opts} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 247 | 0 | %opts = %{ $controller->model_meta->{resultset_opts} }; | |||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||
| 250 | # ORDER BY | ||||||||||||||||||||||||||||||||||
| 251 | #dump $field_names; | ||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | if ( exists $query->{sort_by} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | $opts{order_by} ||= $query->{sort_by}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$opts{"order_by"} ||= $query->{"sort_by"}
MC/DC0%0/2
$opts{"order_by"} ||= $query->{"sort_by"}
$opts{"order_by"}
$query->{"sort_by"}
Truth table0%0/3
A ||= B
A= $opts{"order_by"}B= $query->{"sort_by"}
| |||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||
| 255 | # default is to sort by PK, which might not be prefixed. | ||||||||||||||||||||||||||||||||||
| 256 | 0 | my $ss = Sort::SQL->parse( $opts{order_by} ); | |||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||
| 258 | #dump $ss; | ||||||||||||||||||||||||||||||||||
| 259 | 0 | my @order_by; | |||||||||||||||||||||||||||||||||
| 260 | 0 | for my $clause (@$ss) { | |||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | if ( $clause->[0] !~ m/\./ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | if ( $c->req->params->{'cxc-m2m'} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||
| 265 | # TODO m2m | ||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||
| 268 | else { | ||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||
| 270 | # o2m | ||||||||||||||||||||||||||||||||||
| 271 | 0 | my $name = "me." . $clause->[0]; | |||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if ( grep { $_ eq $name } @$field_names ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 273 | 0 | $clause->[0] = $name; | |||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||
| 277 | 0 | push @order_by, { '-' . lc( $clause->[1] ) => $clause->[0] }; | |||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||
| 279 | 0 | $opts{order_by} = \@order_by; | |||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||
| 282 | #dump \%opts; | ||||||||||||||||||||||||||||||||||
| 283 | 0 | $query->{OPTS} = \%opts; | |||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | $c->log->debug( "query: " . dump $query ) if $c->debug; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||
| 287 | 0 | return $query; | |||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||
| 290 | =head2 make_sql_query( I<controller>, I<context>, I<field_names> ) | ||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||
| 292 | Override method in CatalystX::CRUD::Model::Utils to mimic | ||||||||||||||||||||||||||||||||||
| 293 | ACCEPT_CONTEXT by setting I<context> in $self. | ||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||
| 295 | Otherwise, acts just like CatalystX::CRUD::Model::Utils->make_sql_query(). | ||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||
| 297 | =cut | ||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | sub make_sql_query { | ||||||||||||||||||||||||||||||||
|
Subroutine
make_sql_query: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 300 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 301 | 0 | my $controller = shift; | |||||||||||||||||||||||||||||||||
| 302 | 0 | my $c = shift; | |||||||||||||||||||||||||||||||||
| 303 | 0 | my $field_names = shift; | |||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||
| 305 | # Model::Utils (make_sql_query) assumes ACCEPT_CONTEXT accessor | ||||||||||||||||||||||||||||||||||
| 306 | 0 | $self->{context} = $c; | |||||||||||||||||||||||||||||||||
| 307 | 0 | weaken( $self->{context} ); | |||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||
| 309 | 0 | my $q = $self->next::method($field_names); | |||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||
| 311 | #carp "make_sql_query : " . dump $q; | ||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | if ( $q->{query_obj} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 314 | 0 | $q->{query} = $q->{query_obj}->dbic; | |||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||
| 317 | #carp "make_sql_query : " . dump $q; | ||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||
| 319 | 0 | return $q; | |||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||
| 322 | =head2 search_related( I<controller>, I<context>, I<obj>, I<relationship> [, I<query> ] ) | ||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||
| 324 | Implements required method. Returns array ref of | ||||||||||||||||||||||||||||||||||
| 325 | objects related to I<obj> via I<relationship>. I<relationship> | ||||||||||||||||||||||||||||||||||
| 326 | should be a method name callable on I<obj>. | ||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||
| 328 | =head2 iterator_related( I<controller>, I<context>, I<obj>, I<relationship> [, I<query> ] ) | ||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||
| 330 | Like search_related() but returns an iterator. | ||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||
| 332 | =head2 count_related( I<controller>, I<context>, I<obj>, I<relationship> [, I<query> ] ) | ||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||
| 334 | Like search_related() but returns an integer. | ||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||
| 336 | =cut | ||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | sub search_related { | ||||||||||||||||||||||||||||||||
|
Subroutine
search_related: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 339 | 0 | my ( $self, $controller, $c, $obj, $rel, $query ) = @_; | |||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | $query ||= $self->make_query( $controller, $c ); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$query ||= $self->make_query($controller, $c)
MC/DC0%0/2
$query ||= $self->make_query($controller, $c)
$query
$self->make_query($controller, $c)
Truth table0%0/3
A ||= B
A= $queryB= $self->make_query($controller, $c)
| |||||||||||||||||||||||||||||||||||
| 341 | 0 | return [ $obj->$rel->search( $query->{WHERE}, $query->{OPTS} ) ]; | |||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | sub iterator_related { | ||||||||||||||||||||||||||||||||
|
Subroutine
iterator_related: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 345 | 0 | my ( $self, $controller, $c, $obj, $rel, $query ) = @_; | |||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | $query ||= $self->make_query( $controller, $c ); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$query ||= $self->make_query($controller, $c)
MC/DC0%0/2
$query ||= $self->make_query($controller, $c)
$query
$self->make_query($controller, $c)
Truth table0%0/3
A ||= B
A= $queryB= $self->make_query($controller, $c)
| |||||||||||||||||||||||||||||||||||
| 347 | 0 | return scalar $obj->$rel->search( $query->{WHERE}, $query->{OPTS} ); | |||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | sub count_related { | ||||||||||||||||||||||||||||||||
|
Subroutine
count_related: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 351 | 0 | my ( $self, $controller, $c, $obj, $rel, $query ) = @_; | |||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | $query ||= $self->make_query( $controller, $c ); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$query ||= $self->make_query($controller, $c)
MC/DC0%0/2
$query ||= $self->make_query($controller, $c)
$query
$self->make_query($controller, $c)
Truth table0%0/3
A ||= B
A= $queryB= $self->make_query($controller, $c)
| |||||||||||||||||||||||||||||||||||
| 353 | 0 | return $obj->$rel->count( $query->{WHERE}, $query->{OPTS} ); | |||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||
| 356 | =head2 add_related( I<controller>, I<context>, I<obj>, I<rel_name>, I<foreign_value> ) | ||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||
| 358 | Implements optional method as defined by core API. I<rel_name> | ||||||||||||||||||||||||||||||||||
| 359 | should be a method name callable by I<obj>. | ||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||
| 361 | =cut | ||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | sub add_related { | ||||||||||||||||||||||||||||||||
|
Subroutine
add_related: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 364 | 0 | my ( $self, $controller, $c, $obj, $rel, $for_val ) = @_; | |||||||||||||||||||||||||||||||||
| 365 | 0 | my $rinfo = $self->_get_rel_meta( $controller, $c, $obj, $rel ); | |||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||
| 367 | #carp "add_related: " . dump $rinfo; | ||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | if ( exists $rinfo->{m2m} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 370 | 0 | my $for_obj | |||||||||||||||||||||||||||||||||
| 371 | = $self->_get_m2m_foreign_object( $controller, $c, $obj, $rel, | ||||||||||||||||||||||||||||||||||
| 372 | $rinfo, $for_val ); | ||||||||||||||||||||||||||||||||||
| 373 | 0 | my $add_method = 'add_to_' . $rinfo->{m2m}->{method_name}; | |||||||||||||||||||||||||||||||||
| 374 | 0 | $obj->$add_method($for_obj); | |||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||
| 376 | else { | ||||||||||||||||||||||||||||||||||
| 377 | 0 | croak "TODO o2m"; | |||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | sub _get_m2m_foreign_object { | ||||||||||||||||||||||||||||||||
|
Subroutine
_get_m2m_foreign_object: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 382 | 0 | my ( $self, $controller, $c, $obj, $rel, $rinfo, $for_val ) = @_; | |||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | if ( !exists $rinfo->{m2m} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 384 | 0 | $self->throw_error("relationship $rel is not a many-to-many"); | |||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||
| 387 | #carp "get foreign object $for_val for $rel : " . dump $rinfo; | ||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||
| 389 | 0 | my $m2m = $rinfo->{m2m}; | |||||||||||||||||||||||||||||||||
| 390 | 0 | my $foreign_class = $m2m->{foreign_class}; | |||||||||||||||||||||||||||||||||
| 391 | 0 | my $fpk = $m2m->{foreign_column}; | |||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | my $for_obj | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 393 | = $c->model( $self->model_name )->resultset($foreign_class) | ||||||||||||||||||||||||||||||||||
| 394 | ->find( { $fpk => $for_val } ) | ||||||||||||||||||||||||||||||||||
| 395 | or $self->throw_error( | ||||||||||||||||||||||||||||||||||
| 396 | "can't find foreign object in $foreign_class for $for_val"); | ||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||
| 398 | 0 | return $for_obj; | |||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||
| 401 | =head2 rm_related( I<controller>, I<context>, I<obj>, I<rel_name>, I<foreign_value> ) | ||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||
| 403 | Implements optional method as defined by core API. I<rel_name> | ||||||||||||||||||||||||||||||||||
| 404 | should be a method name callable by I<obj>. | ||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||
| 406 | =cut | ||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | sub rm_related { | ||||||||||||||||||||||||||||||||
|
Subroutine
rm_related: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 409 | 0 | my ( $self, $controller, $c, $obj, $rel, $for_val ) = @_; | |||||||||||||||||||||||||||||||||
| 410 | 0 | my $rinfo = $self->_get_rel_meta( $controller, $c, $obj, $rel ); | |||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||
| 412 | #carp dump $rinfo; | ||||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | if ( exists $rinfo->{m2m} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||
| 415 | # isa m2m | ||||||||||||||||||||||||||||||||||
| 416 | # must find the foreign object to pass to remove_from_$rel() | ||||||||||||||||||||||||||||||||||
| 417 | 0 | my $for_obj | |||||||||||||||||||||||||||||||||
| 418 | = $self->_get_m2m_foreign_object( $controller, $c, $obj, $rel, | ||||||||||||||||||||||||||||||||||
| 419 | $rinfo, $for_val ); | ||||||||||||||||||||||||||||||||||
| 420 | 0 | my $rm_method = 'remove_from_' . $rinfo->{m2m}->{method_name}; | |||||||||||||||||||||||||||||||||
| 421 | 0 | $obj->$rm_method($for_obj); | |||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||
| 424 | else { | ||||||||||||||||||||||||||||||||||
| 425 | 0 | croak "TODO o2m"; | |||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||
| 430 | =head2 has_relationship( I<controller>, I<context>, I<obj>, I<rel_name> ) | ||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||
| 432 | Implements optional method as defined by core API. I<rel_name> | ||||||||||||||||||||||||||||||||||
| 433 | should be a method name callable by I<obj>. | ||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||
| 435 | =cut | ||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||
| 437 | 0 | ▶ | sub has_relationship { | ||||||||||||||||||||||||||||||||
|
Subroutine
has_relationship: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 438 | 0 | my ( $self, $controller, $c, $obj, $rel ) = @_; | |||||||||||||||||||||||||||||||||
| 439 | 0 | eval { $obj->ensure_class_loaded('DBIx::Class::RDBOHelpers'); }; | |||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 441 | 0 | $self->throw_error("DBIx::Class::RDBOHelpers not loaded for $obj"); | |||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||
| 444 | 0 | for ( $obj->relationships ) { | |||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | return $obj->relationship_info($_) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 446 | if $_ eq $rel; | ||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||
| 448 | # m2m relationships are not keyed by their method name | ||||||||||||||||||||||||||||||||||
| 449 | 0 | my $info = $obj->relationship_info($_); | |||||||||||||||||||||||||||||||||
| 450 | 0 | ▶ | if ( exists $info->{m2m} and $info->{m2m}->{method_name} eq $rel ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $info->{"m2m"} and $info->{"m2m"}{"method_name"} eq $rel
MC/DC0%0/2
exists $info->{"m2m"} and $info->{"m2m"}{"method_name"} eq $rel
exists $info->{"m2m"}
$info->{"m2m"}{"method_name"} eq $rel
Truth table0%0/3
A and B
A= exists $info->{"m2m"}B= $info->{"m2m"}{"method_name"} eq $rel
| |||||||||||||||||||||||||||||||||||
| 451 | 0 | return $info; | |||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||
| 454 | 0 | return; | |||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||
| 457 | 0 | ▶ | sub _get_rel_meta { | ||||||||||||||||||||||||||||||||
|
Subroutine
_get_rel_meta: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 458 | 0 | my ( $self, $controller, $c, $obj, $rel ) = @_; | |||||||||||||||||||||||||||||||||
| 459 | 0 | ▶ | if ( !$self->has_relationship( $controller, $c, $obj, $rel ) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 460 | 0 | $self->throw_error("no such relationship $rel defined for $obj"); | |||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | return $self->has_relationship( $controller, $c, $obj, $rel ) | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->has_relationship($controller, $c, $obj, $rel) || $obj->relationship_info($rel)
MC/DC0%0/2
$self->has_relationship($controller, $c, $obj, $rel) || $obj->relationship_info($rel)
$self->has_relationship($controller, $c, $obj, $rel)
$obj->relationship_info($rel)
Truth table0%0/3
A || B
A= $self->has_relationship($controller, $c, $obj, $rel)B= $obj->relationship_info($rel)
| |||||||||||||||||||||||||||||||||||
| 463 | || $obj->relationship_info($rel); | ||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||
| 466 | 0 | ▶ | sub _get_field_names { | ||||||||||||||||||||||||||||||||
|
Subroutine
_get_field_names: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||
| 467 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 468 | 0 | my $controller = shift; | |||||||||||||||||||||||||||||||||
| 469 | 0 | my $c = shift; | |||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||
| 471 | 0 | my $moniker = $self->_get_moniker($c); | |||||||||||||||||||||||||||||||||
| 472 | return $self->{_field_names} | ||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | if exists $self->{_field_names}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||
| 475 | 0 | my $table_obj | |||||||||||||||||||||||||||||||||
| 476 | = $c->model( $self->model_name )->composed_schema->class($moniker); | ||||||||||||||||||||||||||||||||||
| 477 | 0 | my @cols = $table_obj->columns; | |||||||||||||||||||||||||||||||||
| 478 | 0 | my @rels = $table_obj->relationships; | |||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||
| 480 | 0 | my @fields; | |||||||||||||||||||||||||||||||||
| 481 | 0 | for my $rel (@rels) { | |||||||||||||||||||||||||||||||||
| 482 | 0 | my $info = $self->_get_rel_meta( $controller, $c, $table_obj, $rel ); | |||||||||||||||||||||||||||||||||
| 483 | 0 | my ( $rel_class, $prefix ); | |||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||
| 485 | #warn "rel info for $moniker $rel: " . dump $info; | ||||||||||||||||||||||||||||||||||
| 486 | 0 | ▶ | if ( exists $info->{m2m} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 487 | 0 | $rel_class = $info->{m2m}->{foreign_class}; | |||||||||||||||||||||||||||||||||
| 488 | 0 | $prefix = $info->{m2m}->{map_to}; | |||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||
| 490 | else { | ||||||||||||||||||||||||||||||||||
| 491 | 0 | $rel_class = $info->{class}; | |||||||||||||||||||||||||||||||||
| 492 | 0 | $prefix = $rel; | |||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||
| 494 | 0 | my @rel_cols = $rel_class->columns; | |||||||||||||||||||||||||||||||||
| 495 | 0 | push( @fields, map { $prefix . '.' . $_ } @rel_cols ); | |||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||
| 497 | 0 | for my $col (@cols) { | |||||||||||||||||||||||||||||||||
| 498 | 0 | push( @fields, 'me.' . $col ); | |||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||
| 501 | #carp sprintf( "field_names for %s [%s] : %s", | ||||||||||||||||||||||||||||||||||
| 502 | # $moniker, $self->model_name, dump \@fields ); | ||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||
| 504 | 0 | $self->{_field_names} = \@fields; | |||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||
| 506 | 0 | return \@fields; | |||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||
| 509 | =head2 create( I<context>, I<dbic_object> ) | ||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||
| 511 | Calls insert() on I<dbic_object>. | ||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||
| 513 | =cut | ||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||
| 515 | 0 | ▶ | sub create { | ||||||||||||||||||||||||||||||||
|
Subroutine
create: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 516 | 0 | my ( $self, $c, $object ) = @_; | |||||||||||||||||||||||||||||||||
| 517 | 0 | $object->insert; | |||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||
| 520 | =head2 read( I<context>, I<dbic_object> ) | ||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||
| 522 | Calls find() on I<dbic_object>. | ||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||
| 524 | =cut | ||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||
| 526 | 0 | ▶ | sub read { | ||||||||||||||||||||||||||||||||
|
Subroutine
read: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 527 | 0 | my ( $self, $c, $object ) = @_; | |||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||
| 529 | #$object->find; # TODO is this right? what about discard_changes()? | ||||||||||||||||||||||||||||||||||
| 530 | 0 | $c->log->error("TODO $object does not implement find() method"); | |||||||||||||||||||||||||||||||||
| 531 | 0 | return $object; | |||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||
| 534 | =head2 update( I<context>, I<dbic_object> ) | ||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||
| 536 | Calls update() on I<dbic_object>. | ||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||
| 538 | =cut | ||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | sub update { | ||||||||||||||||||||||||||||||||
|
Subroutine
update: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 541 | 0 | my ( $self, $c, $object ) = @_; | |||||||||||||||||||||||||||||||||
| 542 | 0 | $object->update; | |||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||
| 545 | =head2 delete( I<context>, I<dbic_object> ) | ||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||
| 547 | Calls delete() on I<dbic_object>. | ||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||
| 549 | =cut | ||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||
| 551 | 0 | ▶ | sub delete { | ||||||||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 552 | 0 | my ( $self, $c, $object ) = @_; | |||||||||||||||||||||||||||||||||
| 553 | 0 | $object->delete; | |||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||
| 556 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||
| 558 | Peter Karman, C<< <karman at cpan.org> >> | ||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||
| 560 | =head1 BUGS | ||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||
| 562 | Please report any bugs or feature requests to | ||||||||||||||||||||||||||||||||||
| 563 | C<bug-catalystx-crud-modeladapter-dbic at rt.cpan.org>, or through the web interface at | ||||||||||||||||||||||||||||||||||
| 564 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CatalystX-CRUD-ModelAdapter-DBIC>. | ||||||||||||||||||||||||||||||||||
| 565 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||||||||||||||||||||||||||
| 566 | your bug as I make changes. | ||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||
| 568 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||
| 570 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||
| 572 | perldoc CatalystX::CRUD::ModelAdapter::DBIC | ||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||
| 574 | You can also look for information at: | ||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||
| 576 | =over 4 | ||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||
| 578 | =item * Mailing List | ||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||
| 580 | L<https://groups.google.com/forum/#!forum/catalystxcrud> | ||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||
| 582 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||
| 584 | L<http://annocpan.org/dist/CatalystX-CRUD-ModelAdapter-DBIC> | ||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||
| 586 | =item * CPAN Ratings | ||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||
| 588 | L<http://cpanratings.perl.org/d/CatalystX-CRUD-ModelAdapter-DBIC> | ||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||
| 590 | =item * RT: CPAN's request tracker | ||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||
| 592 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CatalystX-CRUD-ModelAdapter-DBIC> | ||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||
| 594 | =item * Search CPAN | ||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||
| 596 | L<http://search.cpan.org/dist/CatalystX-CRUD-ModelAdapter-DBIC> | ||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||
| 598 | =back | ||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||
| 600 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||
| 602 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||
| 604 | Copyright 2008 Peter Karman, all rights reserved. | ||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||
| 606 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||
| 607 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||
| 609 | =cut | ||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||
| 611 | 3 | 1; | |||||||||||||||||||||||||||||||||