-
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.
- Loading branch information
Arthur Axel 'fREW' Schmidt
committed
May 9, 2015
1 parent
5642ffd
commit 1203068
Showing
3 changed files
with
94 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package DBIx::Class::Helper::Schema::Verifier::Parent; | ||
|
||
# ABSTRACT: Verify that the Results and ResultSets have the correct base class | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use MRO::Compat; | ||
use mro 'c3'; | ||
|
||
use base 'DBIx::Class::Helper::Schema::Verifier'; | ||
|
||
sub result_verifiers { | ||
( | ||
sub { | ||
my ($s, $result, $set) = @_; | ||
|
||
my $base_result = $s->base_result; | ||
my $base_set = $s->base_resultset; | ||
|
||
die "$result is not a $base_result" unless $result->isa($base_result); | ||
die "$set is not a $base_set" unless $set->isa($base_set); | ||
}, | ||
shift->next::method, | ||
) | ||
} | ||
|
||
sub base_result { 'DBIx::Class::Core' } | ||
sub base_resultset { 'DBIx::Class::ResultSet' } | ||
|
||
1; | ||
|
||
=head1 SYNOPSIS | ||
package MyApp::Schema; | ||
__PACKAGE__->load_components('Helper::Schema::Verifier::Parent'); | ||
sub base_result { 'MyApp::Schema::Result' } | ||
sub base_resultset { 'MyApp::Schema::ResultSet' } | ||
=head1 DESCRIPTION | ||
C<DBIx::Class::Helper::Schema::Verifier::Parent> verifies that all of your | ||
results and resultsets use the base class that you specify. |
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,48 @@ | ||
use strict; | ||
use warnings; | ||
|
||
use lib 't/lib'; | ||
use Test::More; | ||
use Test::Fatal; | ||
|
||
is(exception { | ||
TSchema->$_('TPassResult', 'TPassResultSet') for TSchema->result_verifiers; | ||
}, undef, 'Result and Set are fine'); | ||
|
||
like(exception { | ||
TSchema->$_('TFailResult', 'TPassResultSet') for TSchema->result_verifiers; | ||
}, qr/^TFailResult is not a Herp/, 'Result fails'); | ||
|
||
like(exception { | ||
TSchema->$_('TPassResult', 'TFailResultSet') for TSchema->result_verifiers; | ||
}, qr/^TFailResultSet is not a Derp/, 'ResultSet fails'); | ||
|
||
done_testing; | ||
|
||
BEGIN { | ||
package TSchema; | ||
|
||
use base 'DBIx::Class::Helper::Schema::Verifier::Parent'; | ||
|
||
sub base_result { 'Herp' } | ||
sub base_resultset { 'Derp' } | ||
|
||
package Herp; | ||
use Moo; | ||
package Derp; | ||
use Moo; | ||
|
||
package TPassResult; | ||
|
||
use base 'Herp'; | ||
|
||
package TPassResultSet; | ||
|
||
use base 'Derp'; | ||
|
||
package TFailResult; | ||
use Moo; | ||
package TFailResultSet; | ||
use Moo; | ||
} | ||
|