File Coverage

blib/lib/DBIx/Class/Smooth/Helper/Row/JoinTable.pm
Criterion Covered Total %
statement 53 53 100.0
branch n/a
condition n/a
subroutine 12 12 100.0
pod 0 1 0.0
total 65 66 98.4


line stmt bran cond sub pod time code
1 2     2   1099 use 5.20.0;
  2         10  
2 2     2   14 use strict;
  2         5  
  2         96  
3 2     2   13 use warnings;
  2         4  
  2         115  
4              
5             package DBIx::Class::Smooth::Helper::Row::JoinTable;
6              
7             # ABSTRACT: Short intro
8             our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
9             our $VERSION = '0.0101';
10              
11 2     2   12 use parent 'DBIx::Class::Row';
  2         6  
  2         12  
12 2     2   130 use String::CamelCase;
  2         5  
  2         67  
13 2     2   20 use Module::Loader;
  2         4  
  2         59  
14 2     2   13 use Syntax::Keyword::Try;
  2         14  
  2         14  
15 2     2   102 use Carp qw/croak/;
  2         4  
  2         130  
16 2     2   15 use DBIx::Class::Candy::Exports;
  2         4  
  2         16  
17 2     2   818 use DBIx::Class::Smooth::Helper::Util qw/result_source_to_class result_source_to_relation_name clean_source_name/;
  2         5  
  2         19  
18              
19 2     2   252 use experimental qw/postderef signatures/;
  2         8  
  2         14  
20              
21             export_methods [qw/
22             join_table
23             /];
24              
25             state $module_loader = Module::Loader->new;
26              
27 2     2 0 11813 sub join_table($self, $left_source, $right_source) {
  2         6  
  2         7  
  2         4  
  2         4  
28              
29 2         8 my $left_class = result_source_to_class($self, $left_source);
30 2         7 my $right_class = result_source_to_class($self, $right_source);
31 2         6 my $via_class = $self;
32              
33 2         6 my $to_via_relation_name = result_source_to_relation_name($via_class, 1);
34 2         8 my $via_to_right_relation_name = result_source_to_relation_name($right_source, 0);
35 2         7 my $left_to_right_relation_name = result_source_to_relation_name($right_source, 1);
36 2         7 my $via_to_left_relation_name = result_source_to_relation_name($left_source, 0);
37 2         9 my $right_to_left_relation_name = result_source_to_relation_name($left_source, 1);
38              
39 2         6 my $left_column_name_in_via = $via_to_left_relation_name . '_id';
40 2         6 my $right_column_name_in_via = $via_to_right_relation_name . '_id';
41              
42 2         19 $via_class->primary_belongs($left_source, { _smooth_foreign_key => 1 });
43 2         363 $via_class->primary_belongs($right_source, { _smooth_foreign_key => 1 });
44              
45 2         367 $module_loader->load($left_class);
46 2         80 $module_loader->load($right_class);
47              
48 2         125 $left_class->many_to_many($left_to_right_relation_name, $to_via_relation_name, $via_to_right_relation_name);
49 2         338 $right_class->many_to_many($right_to_left_relation_name, $to_via_relation_name, $via_to_left_relation_name);
50             }
51              
52             1;
53              
54             __END__
55              
56             =pod
57              
58             =encoding UTF-8
59              
60             =head1 NAME
61              
62             DBIx::Class::Smooth::Helper::Row::JoinTable - Short intro
63              
64             =head1 VERSION
65              
66             Version 0.0101, released 2018-11-29.
67              
68             =head1 SOURCE
69              
70             L<https://github.com/Csson/p5-DBIx-Class-Smooth>
71              
72             =head1 HOMEPAGE
73              
74             L<https://metacpan.org/release/DBIx-Class-Smooth>
75              
76             =head1 AUTHOR
77              
78             Erik Carlsson <info@code301.com>
79              
80             =head1 COPYRIGHT AND LICENSE
81              
82             This software is copyright (c) 2018 by Erik Carlsson.
83              
84             This is free software; you can redistribute it and/or modify it under
85             the same terms as the Perl 5 programming language system itself.
86              
87             =cut