Helper/Schema/Verifier/RelationshipColumnName.pm

filter: Statementstmt 100% 28 / 28 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 100% 40 / 40 CC 3 SCAR 5.1
CC
3
Cov
100%
__ANON__
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.7
« Helper/Schema/Verifier/C3.pm ↑ Summary Helper/Schema/DidYouMean.pm »
1 package DBIx::Class::Helper::Schema::Verifier::RelationshipColumnName;
2 1 $DBIx::Class::Helper::Schema::Verifier::RelationshipColumnName::VERSION = '2.032002';
3 # ABSTRACT: Verify that relationships and column names are distinct
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use MRO::Compat;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use base 'DBIx::Class::Helper::Schema::Verifier';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub result_verifiers {
14 (
15 sub {
16 3 ▶ my ($s, $result) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
17  
18 3 my @columns = $result->columns;
19 3 my %relationships = map { $_ => 1 } $result->relationships;
20  
21 3 my @mistakes = grep { $relationships{$_} } @columns;
22  
23  
24 3 my $exp = 'See DBIx::Class::Helper::Schema::Verifier::RelationshipColumnName for more details';
25 3 ▶ if (@mistakes == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@mistakes == 1) { } 1 2 3
elsif (@mistakes) { } 1 1 2
26 1 die "$result has a relationship name that is the same as a column name: @mistakes, $exp"
27 } elsif (@mistakes) {
28 1 die "$result has relationship names that are the same as column names: @mistakes, $exp"
29 }
30 },
31 shift->next::method,
32 )
33 3 ▶}
Subroutine result_verifiers: called CC=1 SCAR=0.0
Pod documented
34  
35 1 1;
36  
37 __END__
38  
39 =pod
40  
41 =head1 NAME
42  
43 DBIx::Class::Helper::Schema::Verifier::RelationshipColumnName - Verify that relationships and column names are distinct
44  
45 =head1 SYNOPSIS
46  
47 package MyApp::Schema;
48  
49 __PACKAGE__->load_components('Helper::Schema::Verifier::RelationshipColumnName');
50  
51 =head1 DESCRIPTION
52  
53 C<DBIx::Class::Helper::Schema::Verifier::RelationshipColumnName> verifies that
54 none of your columns have the same name as a relationship. If you create a
55 relationship that has the same name as a column, to access the column you will
56 be forced to use C<get_column>, additionally it is just confusing having them
57 be the same name. What I tend to do is define the columns to be something like
58 C<user_id> and have the relationship then be simply C<user>.
59  
60 =head1 AUTHOR
61  
62 Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
63  
64 =head1 COPYRIGHT AND LICENSE
65  
66 This software is copyright (c) 2016 by Arthur Axel "fREW" Schmidt.
67  
68 This is free software; you can redistribute it and/or modify it under
69 the same terms as the Perl 5 programming language system itself.
70  
71 =cut
« Helper/Schema/Verifier/C3.pm ↑ Summary Helper/Schema/DidYouMean.pm »