DBIx/Class/Relationship/ProxyMethods.pm

filter: Statementstmt 100% 32 / 32 Branchbran 100% 10 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 96.1% 50 / 52 CC 7 SCAR 10.0
CC
7
Cov
100%
_build_proxy_map_from
5.0
register_relationship
2.0
proxy_to_related
2.0
CRAP 2.7
« DBIx/Class/ResultSetManager.pm ↑ Summary DBIx/Class/Storage/DBI/IdentityInsert.pm »
1 package # hide from PAUSE
2 DBIx::Class::Relationship::ProxyMethods;
3  
4 379 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 379 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 379 ▶use base 'DBIx::Class';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 379 ▶use DBIx::Class::_Util 'quote_sub';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 379 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 379 our %_pod_inherit_config =
11 (
12 class_map => { 'DBIx::Class::Relationship::ProxyMethods' => 'DBIx::Class::Relationship' }
13 );
14  
15 29086 ▶sub register_relationship {
Subroutine register_relationship: called CC=2 SCAR=6.9
Pod undocumented
16 29086 my ($class, $rel, $info) = @_;
17 29086 ▶ if (my $proxy_args = $info->{attrs}{proxy}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $proxy_args = $info->{"attrs"}{"proxy"}) 1978 27108 29086
18 1978 $class->proxy_to_related($rel, $proxy_args);
19 }
20 29084 $class->next::method($rel, $info);
21 }
22  
23 1978 ▶sub proxy_to_related {
Subroutine proxy_to_related: called CC=2 SCAR=6.9
Pod undocumented
24 1978 my ($class, $rel, $proxy_args) = @_;
25 1978 my %proxy_map = $class->_build_proxy_map_from($proxy_args);
26  
27 quote_sub "${class}::$_", sprintf( <<'EOC', $rel, $proxy_map{$_} )
28 my $self = shift;
29 my $relobj = $self->%1$s;
30 if (@_ && !defined $relobj) {
31 $relobj = $self->create_related( %1$s => { %2$s => $_[0] } );
32 @_ = ();
33 }
34 $relobj ? $relobj->%2$s(@_) : undef;
35 EOC
36 1976 for keys %proxy_map
37 }
38  
39 1978 ▶sub _build_proxy_map_from {
Subroutine _build_proxy_map_from: called CC=5 SCAR=16.1
40 1978 my ( $class, $proxy_arg ) = @_;
41 1978 my $ref = ref $proxy_arg;
42  
43 1978 ▶ if ($ref eq 'HASH') {
Branch: 3 branches
BranchTrueFalseTotal
if ($ref eq 'HASH') { } 988 990 1978
elsif ($ref eq 'ARRAY') { } 661 329 990
elsif ($ref) { } 2 327 329
44 988 return %$proxy_arg;
45 }
46 elsif ($ref eq 'ARRAY') {
47 return map {
48 661 ▶ (ref $_ eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'HASH' ? : 325 661 986
49 ? (%$_)
50 : ($_ => $_)
51 } @$proxy_arg;
52 }
53 elsif ($ref) {
54 2 $class->throw_exception("Unable to process the 'proxy' argument $proxy_arg");
55 }
56 else {
57 327 return ( $proxy_arg => $proxy_arg );
58 }
59 }
60  
61 379 1;
« DBIx/Class/ResultSetManager.pm ↑ Summary DBIx/Class/Storage/DBI/IdentityInsert.pm »