File Coverage

blib/lib/DBIx/Class/Helper/Row/RelationshipDWIM.pm
Criterion Covered Total %
statement 25 26 96.1
branch n/a
condition n/a
subroutine 7 8 87.5
pod 0 5 0.0
total 32 39 82.0


line stmt bran cond sub pod time code
1             package DBIx::Class::Helper::Row::RelationshipDWIM;
2             $DBIx::Class::Helper::Row::RelationshipDWIM::VERSION = '2.035000';
3             # ABSTRACT: Type less for your relationships!
4              
5 57     57   5718991 use strict;
  57         280  
  57         1709  
6 57     57   327 use warnings;
  57         133  
  57         1642  
7              
8 57     57   1678 use parent 'DBIx::Class::Row';
  57         174  
  57         319  
9              
10             sub default_result_namespace {
11 0     0 0 0 die 'you forgot to set your default_result_namespace'
12             }
13              
14             sub belongs_to {
15 57     57 0 381080 my ( $self, @args ) = @_;
16              
17 57         390 $args[1] =~ s/^::/$self->default_result_namespace . '::'/e;
  57         377  
18              
19 57         552 $self->next::method(@args);
20             }
21              
22             sub has_many {
23 57     57 0 213048 my ( $self, @args ) = @_;
24              
25 57         401 $args[1] =~ s/^::/$self->default_result_namespace . '::'/e;
  57         290  
26              
27 57         715 $self->next::method(@args);
28             }
29              
30             sub might_have {
31 57     57 0 33716 my ( $self, @args ) = @_;
32              
33 57         414 $args[1] =~ s/^::/$self->default_result_namespace . '::'/e;
  57         1677  
34              
35 57         469 $self->next::method(@args);
36             }
37              
38             sub has_one {
39 57     57 0 52339 my ( $self, @args ) = @_;
40              
41 57         457 $args[1] =~ s/^::/$self->default_result_namespace . '::'/e;
  57         295  
42              
43 57         524 $self->next::method(@args);
44             }
45              
46             1;
47              
48             __END__
49              
50             =pod
51              
52             =head1 NAME
53              
54             DBIx::Class::Helper::Row::RelationshipDWIM - Type less for your relationships!
55              
56             =head1 SYNOPSIS
57              
58             Base clase:
59              
60             package MyApp::Schema::Result;
61              
62             use parent 'DBIx::Class::Core';
63              
64             __PACKAGE__->load_components('Helper::Row::RelationshipDWIM');
65              
66             sub default_result_namespace { 'MyApp::Schema::Result' }
67              
68             1;
69              
70             Result class:
71              
72             package MyApp::Schema::Result::Foo;
73              
74             use parent 'MyApp::Schema::Result';
75              
76             # Define various class bits here
77              
78             # succinct relationship definition yeah!
79              
80             __PACKAGE__->has_many(friends => '::Person', 'foo_id');
81              
82             # or with DBIx::Class::Candy:
83             has_many friends => '::Person', 'foo_id';
84              
85             1;
86              
87             =head1 DESCRIPTION
88              
89             This module prepends your C<default_result_namespace> to related objects if they
90             begin with C<::>. Simple but handy.
91              
92             =head1 AUTHOR
93              
94             Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
95              
96             =head1 COPYRIGHT AND LICENSE
97              
98             This software is copyright (c) 2020 by Arthur Axel "fREW" Schmidt.
99              
100             This is free software; you can redistribute it and/or modify it under
101             the same terms as the Perl 5 programming language system itself.
102              
103             =cut