Types::DBIx::Class - A Type::Library for DBIx::Class objects
version 1.00000
# Standalone, no object library required use Types::DBIx::Class -all; if (! is_Schema( $some_obj ) ) { die '$some_obj is not a DBIx Schema ' } my $validator = (Row['my_table'])->compiled_check; my $is_valid = $validator->( $should_be_a_row_from_my_table ); ResultSet['some_class']->assert_valid( $results ); # Dies if $results fails # in your Moo/Mouse/Moose class use Types::DBIx::Class qw(ResultSet Row); # non-parameterized usage has any_resultset => ( is => 'ro', isa => ResultSet ); # this attribute must be a DBIx::Class::ResultSet object from your "Album" ResultSet class has albums_rs => ( is => 'ro', isa => ResultSet['Album'] ); # this attribute must be a DBIx::Class::Row object from your "Album" Result class has album => ( is => 'ro', isa => Row['Album'] ); # subtyping works as expected use Type::Library -declare => [qw(RockAlbum DecadeAlbum)]; subtype RockAlbum, as Row['Album'], where { $_->genre eq 'Rock' }; # Further parameterization! package Local::MyAlbumTypes; use Type::Library -base; use Type::Utils -all; declare 'DecadeAlbum', parent => Row['Album'], constraint_generator => sub { my ($decade) = @_; die "Decade must be an Int between 0 and 100" unless $decade =~ /^\d+$/ && $decade < 100; $decade = substr($decade,0,1); return sub { substr($_->year,-2,1) eq $decade } }; # In another module use Moo; use Type::Tiny; use Local::MyAlbumTypes; my $EightiesRock = Type::Tiny->new( name => 'EightiesRock', parent => DecadeAlbum[80], constraint => sub { $_->genre eq 'Rock' } ); has eighties_rock_album => ( is => 'ro', isa => $EightiesRock, );
This simply provides some Type::Tiny style types for often shared DBIx::Class objects. It is forked from, and still borrows heavily from MooseX::Types::DBIx::Class.
Each of the types below first ensures the appropriate isa relationship. If the (optional) parameter is specified, it constrains the value further in some way. These types do not define any coercions.
isa
Additionaly, each provieds stand-alone validation subroutines via Type::Tiny, which do not require using an object framework.
This type constraint requires the object to be an instance of DBIx::Class::ResultSet and to have the specified $source_name (if specified).
$source_name
This type constraint requires the object to be an instance of DBIx::Class::ResultSource and to have the specified $source_name (if specified).
This type constraint requires the object to be an instance of DBIx::Class::Row and to have the specified $source_name (if specified).
This type constraint is present mostly for completeness and requires the object to be an instance of DBIx::Class::Schema and to have a class name that matches $class_name or the regular expression if specified.
$class_name
Type::Tiny, Type::Library
Yary Hluchan <yary@cpan.org>
Authors of the original MooseX::Types::DBIx::Class module, which this module copies from copiously:
Oliver Charles <oliver@ocharles.org.uk> Brian Phillips <bphillips@cpan.org>
This software is copyright (c) 2015 by Yary Hluchan
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Types::DBIx::Class, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Types::DBIx::Class
CPAN shell
perl -MCPAN -e shell install Types::DBIx::Class
For more information on module installation, please visit the detailed CPAN module installation guide.