File Coverage

blib/lib/DBIx/Class/AccessorGroup.pm
Criterion Covered Total %
statement 53 54 98.1
branch 13 16 81.2
condition 9 12 75.0
subroutine 14 14 100.0
pod 3 5 60.0
total 92 101 91.0


line stmt bran cond sub pod time code
1             package DBIx::Class::AccessorGroup;
2              
3 313     313   2489 use strict;
  313         786  
  313         9592  
4 313     313   1807 use warnings;
  313         734  
  313         9520  
5              
6 313     313   1728 use base qw( DBIx::Class::MethodAttributes Class::Accessor::Grouped );
  313         726  
  313         106755  
7              
8 313     313   1786454 use Scalar::Util 'blessed';
  313         944  
  313         16188  
9 313     313   2142 use DBIx::Class::_Util 'fail_on_internal_call';
  313         789  
  313         13535  
10 313     313   2018 use namespace::clean;
  313         735  
  313         2186  
11              
12             sub mk_classdata :DBIC_method_is_indirect_sugar {
13 290     290 0 5343 DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_INDIRECT_CALLS and fail_on_internal_call;
14 290         3670 shift->mk_classaccessor(@_);
15 313     313   88108 }
  313         839  
  313         3716  
16              
17             sub mk_classaccessor :DBIC_method_is_indirect_sugar {
18 3092     3092 0 8643 my $self = shift;
19 3092         16740 $self->mk_group_accessors('inherited', $_[0]);
20 3092 50       27129 (@_ > 1)
21             ? $self->set_inherited(@_)
22             : ( DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_INDIRECT_CALLS and fail_on_internal_call )
23             ;
24 313     313   82470 }
  313         842  
  313         1336  
25              
26             sub mk_group_accessors {
27 50412     50412 1 152605 my $class = shift;
28 50412         81942 my $type = shift;
29              
30 50412         273794 $class->next::method($type, @_);
31              
32             # label things
33 50412 100       21264983 if( $type =~ /^ ( inflated_ | filtered_ )? column $/x ) {
    50          
34              
35 41369 100       126170 $class = ref $class
36             if length ref $class;
37              
38 41369         96529 for my $acc_pair (
39             map
40 41369         171011 { [ $_, "_${_}_accessor" ] }
41             map
42 41369 100       146429 { ref $_ ? $_->[0] : $_ }
43             @_
44             ) {
45              
46 41369         79613 for my $i (0, 1) {
47              
48 82738         4324656 my $acc_name = $acc_pair->[$i];
49              
50 82738 100 33     941031 attributes->import(
51             $class,
52             (
53             $class->can($acc_name)
54             ||
55             Carp::confess("Accessor '$acc_name' we just created on $class can't be found...?")
56             ),
57             'DBIC_method_is_generated_from_resultsource_metadata',
58             ($i
59             ? "DBIC_method_is_${type}_extra_accessor"
60             : "DBIC_method_is_${type}_accessor"
61             ),
62             )
63             }
64             }
65             }
66             elsif( $type eq 'inherited_ro_instance' ) {
67 0         0 DBIx::Class::Exception->throw(
68             "The 'inherted_ro_instance' CAG group has been retired - use 'inherited' instead"
69             );
70             }
71             }
72              
73             sub get_component_class {
74 4695     4695 1 162932 my $class = $_[0]->get_inherited($_[1]);
75              
76 313     313   128586 no strict 'refs';
  313         912  
  313         56933  
77 4695 100 66     282060 if (
      100        
      100        
78             defined $class
79             and
80             # inherited CAG can't be set to undef effectively, so people may use ''
81             length $class
82             and
83             # It's already an object, just go for it.
84             ! defined blessed $class
85             and
86 4233         32016 ! ${"${class}::__LOADED__BY__DBIC__CAG__COMPONENT_CLASS__"}
87             ) {
88 369         3152 $_[0]->ensure_class_loaded($class);
89              
90 368         2034 ${"${class}::__LOADED__BY__DBIC__CAG__COMPONENT_CLASS__"}
91 368         2431 = do { \(my $anon = 'loaded') };
  368         1400  
92             }
93              
94 4694         32050 $class;
95             };
96              
97             sub set_component_class {
98 1960     1960 1 3527734 $_[0]->set_inherited($_[1], $_[2]);
99              
100             # trigger a load for the case of $foo->component_accessor("bar")->new
101 1960 50       25915 $_[0]->get_component_class($_[1])
102             if defined wantarray;
103             }
104              
105             1;
106              
107             =head1 NAME
108              
109             DBIx::Class::AccessorGroup - See Class::Accessor::Grouped
110              
111             =head1 SYNOPSIS
112              
113             =head1 DESCRIPTION
114              
115             This class now exists in its own right on CPAN as Class::Accessor::Grouped
116              
117             =head1 FURTHER QUESTIONS?
118              
119             Check the list of L.
120              
121             =head1 COPYRIGHT AND LICENSE
122              
123             This module is free software L
124             by the L. You can
125             redistribute it and/or modify it under the same terms as the
126             L.
127              
128             =cut