-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new ::Schema::Verifier framework
- Loading branch information
Arthur Axel 'fREW' Schmidt
committed
May 2, 2015
1 parent
cf9f359
commit 1adc477
Showing
8 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package DBIx::Class::Helper::Schema::Verifier; | ||
|
||
# ABSTRACT: Verify the Results and ResultSets of your Schemata | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use MRO::Compat; | ||
use mro 'c3'; | ||
|
||
use base 'DBIx::Class::Schema'; | ||
|
||
sub result_verifiers { | ||
return () | ||
} | ||
|
||
sub register_source { | ||
my ($self, $name, $rclass) = @_; | ||
|
||
$self->$_($rclass->result_class, $rclass->resultset_class) | ||
for $self->result_verifiers; | ||
|
||
$self->next::method($name, $rclass); | ||
} | ||
|
||
1; | ||
|
||
=head1 SYNOPSIS | ||
package MyApp::Schema; | ||
__PACKAGE__->load_components('Helper::Schema::Verifier'); | ||
sub result_verifiers { | ||
( | ||
sub { | ||
my ($self, $result, $set) = @_; | ||
for ($result, $set) { | ||
die "$_ does not start with the letter A" unless m/^A/ | ||
} | ||
}, | ||
shift->next::method, | ||
) | ||
} | ||
=head1 DESCRIPTION | ||
C<DBIx::Class::Helper::Schema::Verifier> is a miniscule framework to assist in | ||
creating schemata that are to your very own exacting specifications. It is | ||
inspired by my own travails in discovering that C<< use mro 'c3' >> is both | ||
required and barely documented in much Perl code. As time goes by I expect to | ||
add many more verifiers, but with this inaugural release I am merely including | ||
L<DBIx::Class::Helper::Schema::Verifier::C3>. | ||
=head1 INTERFACE METHODS | ||
=head2 result_verifiers | ||
You must implement C<result_verifiers> in your subclass of C<::Verifier>. Each | ||
verifier gets called on the schema and gets each result and resultset together | ||
as arguments. You can use this to validate almost anything about the results | ||
and resultsets of a schema; contributions are warmly welcomed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use strict; | ||
use warnings; | ||
|
||
use lib 't/lib'; | ||
use Test::More; | ||
use Test::Fatal; | ||
|
||
like(exception { | ||
require VerifySchema; | ||
}, qr/^Derp/, 'Schema verify checks all input'); | ||
|
||
done_testing; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package Herp; | ||
|
||
sub noise {} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package VerifySchema; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use MRO::Compat; | ||
use mro 'c3'; | ||
|
||
use parent 'DBIx::Class::Schema'; | ||
|
||
sub result_verifiers { | ||
(sub { | ||
my ($s, $result, $set) = @_; | ||
|
||
die 'Derp' if $set->isa('Herp'); | ||
}, shift->next::method) | ||
} | ||
|
||
__PACKAGE__->load_components(qw( | ||
Helper::Schema::Verifier | ||
)); | ||
|
||
__PACKAGE__->load_namespaces; | ||
|
||
'zomg'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package VerifySchema::Result::A; | ||
|
||
use DBIx::Class::Candy -base => 'DBIx::Class::Core'; | ||
|
||
table 'A'; | ||
|
||
column id => { | ||
data_type => 'integer', | ||
size => 12, | ||
}; | ||
|
||
primary_key 'id'; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package VerifySchema::ResultSet::A; | ||
|
||
use DBIx::Class::Candy::ResultSet; | ||
|
||
use base 'Herp'; | ||
|
||
1; |