File Coverage

blib/lib/DBICx/AutoDoc/Magic.pm
Criterion Covered Total %
statement 12 35 34.2
branch 0 2 0.0
condition 0 3 0.0
subroutine 4 10 40.0
pod 5 5 100.0
total 21 55 38.1


line stmt bran cond sub pod time code
1             package DBICx::AutoDoc::Magic;
2 1     1   5 use strict;
  1         1  
  1         25  
3 1     1   3 use warnings;
  1         2  
  1         38  
4             our $VERSION = '0.08';
5 1     1   420 use DBIx::Class::Relationship::Helpers;
  1         36601  
  1         33  
6 1     1   6 use base qw( DBIx::Class );
  1         2  
  1         216  
7              
8             __PACKAGE__->mk_group_accessors( inherited => qw( _autodoc ) );
9              
10             my $func_body = <<'END';
11             my $self = shift;
12             $self->_autodoc_record_relationship( @_ );
13             $self->maybe::next::method( @_ );
14             END
15              
16 0     0 1   eval "sub $_ { $func_body }" for qw(
  0     0 1    
  0     0 1    
  0     0 1    
  0     0 1    
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
17             has_many has_one might_have belongs_to many_to_many
18             );
19              
20             # This needs to go after the stuff above, so Class::C3 can figure out the
21             # methods in this class
22             DBIx::Class::Relationship::Helpers->load_components( '+DBICx::AutoDoc::Magic' );
23              
24             sub _autodoc_record_relationship {
25 0     0     my $self = shift;
26              
27 0           my ( $method ) = ( caller( 1 ) )[3];
28 0           $method =~ s/^.*:://;
29              
30 0   0       my $class = ref( $self ) || $self;
31 0 0         if ( ! $class->_autodoc ) { $class->_autodoc( {} ) }
  0            
32              
33 0           push( @{ $class->_autodoc->{ 'relationships' } }, [ $method, @_ ] );
  0            
34             }
35              
36             1;
37              
38             __END__