Helper/Schema/Verifier.pm

filter: Statementstmt 86.3% 38 / 44 Branchbran 33.3% 2 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 92.3% 12 / 13 Podpod 100% 4 / 4 totaltotal 83.5% 56 / 67 CC 6 SCAR 8.6
CC
6
Cov
80%
load_classes
6.0
register_source
4.1
load_namespaces
2.0
CRAP 2.4
« Helper/ResultSet/Explain.pm ↑ Summary Helper/Row/ProxyResultSetMethod.pm »
1 package DBIx::Class::Helper::Schema::Verifier;
2 4 $DBIx::Class::Helper::Schema::Verifier::VERSION = '2.032002';
3 # ABSTRACT: Verify the Results and ResultSets of your Schemata
4  
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use MRO::Compat;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 4 ▶use base 'DBIx::Class::Schema';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 sub result_verifiers {
17 return ()
18 11 ▶}
Subroutine result_verifiers: called CC=1 SCAR=0.0
Pod documented
19  
20 4 our $_FATAL = 1;
21 4 our @_ERRORS;
22  
23 sub register_source {
24 2 ▶ my ($self, $name, $rclass) = @_;
Subroutine register_source: called CC=4 SCAR=14.2
Pod documented
25  
26 2 ▶ unless ($_FATAL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DBIx::Class::Helper::Schema::Verifier::_FATAL) { } 2 0 2
27 $self->$_($rclass->result_class, $rclass->resultset_class)
28 0 for $self->result_verifiers;
29 } else {
30 2 for ($self->result_verifiers) {
31 try {
32 4 ▶ $self->$_($rclass->result_class, $rclass->resultset_class)
Subroutine __ANON__: called CC=1 SCAR=0.0
33 } catch {
34 4 ▶ push @_ERRORS, $_
Subroutine __ANON__: called CC=1 SCAR=0.0
35 }
36 4 }
37 }
38  
39 2 $self->next::method($name, $rclass);
40 }
41  
42 sub load_namespaces {
43 1 ▶ local $_FATAL = 1;
Subroutine load_namespaces: called CC=2 SCAR=7.0
Pod documented
44  
45 1 shift->next::method(@_);
46  
47 1 my @e = @_ERRORS;
48 1 @_ERRORS = ();
49 1 ▶ die sort @e if @e;
Branch: 1 branch
BranchTrueFalseTotal
if @e 1 0 1
50 }
51  
52 sub load_classes {
53 0 ▶ local $_FATAL = 1;
Subroutine load_classes: not called CC=2 SCAR=17.9
Pod documented
54  
55 0 shift->next::method(@_);
56  
57 0 my @e = @_ERRORS;
58 0 @_ERRORS = ();
59 0 ▶ die sort @e if @e;
Branch: 1 branch
BranchTrueFalseTotal
if @e 0 0 0
60 }
61  
62 4 1;
63  
64 __END__
65  
66 =pod
67  
68 =head1 NAME
69  
70 DBIx::Class::Helper::Schema::Verifier - Verify the Results and ResultSets of your Schemata
71  
72 =head1 SYNOPSIS
73  
74 package MyApp::Schema;
75  
76 __PACKAGE__->load_components('Helper::Schema::Verifier');
77  
78 sub result_verifiers {
79 (
80 sub {
81 my ($self, $result, $set) = @_;
82  
83 for ($result, $set) {
84 die "$_ does not start with the letter A" unless m/^A/
85 }
86 },
87 shift->next::method,
88 )
89 }
90  
91 =head1 DESCRIPTION
92  
93 C<DBIx::Class::Helper::Schema::Verifier> is a miniscule framework to assist in
94 creating schemata that are to your very own exacting specifications. It is
95 inspired by my own travails in discovering that C<< use mro 'c3' >> is both
96 required and barely documented in much Perl code. As time goes by I expect to
97 add many more verifiers, but with this inaugural release I am merely including
98 L<DBIx::Class::Helper::Schema::Verifier::C3>.
99  
100 =head1 INTERFACE METHODS
101  
102 =head2 result_verifiers
103  
104 You must implement C<result_verifiers> in your subclass of C<::Verifier>. Each
105 verifier gets called on the schema and gets each result and resultset together
106 as arguments. You can use this to validate almost anything about the results
107 and resultsets of a schema; contributions are warmly welcomed.
108  
109 =head1 MORE ERRORS
110  
111 Initially I kept this module simple, but after using it in production at
112 L<ZipRecruiter|https://www.ziprecruiter.com> I found that showing the user the
113 first error that occured and then giving up was pretty annoying. Now
114 C<Schema::Verifier> wraps both L<DBIx::Class::Schema/load_namespaces> and
115 L<DBIx::Class::Schema/load_classes> and shows all the exceptions encoutered as a
116 list at the end of loading all the results.
117  
118 =head1 AUTHOR
119  
120 Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
121  
122 =head1 COPYRIGHT AND LICENSE
123  
124 This software is copyright (c) 2016 by Arthur Axel "fREW" Schmidt.
125  
126 This is free software; you can redistribute it and/or modify it under
127 the same terms as the Perl 5 programming language system itself.
128  
129 =cut
« Helper/ResultSet/Explain.pm ↑ Summary Helper/Row/ProxyResultSetMethod.pm »