The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MooseX::Types::DBIx::Class - MooseX::Types for DBIx::Class objects

VERSION

version 0.05

SYNOPSIS

    # in your Moose class
    use MooseX::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 MooseX::Types -declare => [qw(RockAlbum DecadeAlbum)];
    use Moose::Util::TypeConstraints;

    subtype RockAlbum,
        as Row['Album'],
        where { $_->genre eq 'Rock' };

    # Further parameterization!
    use MooseX::Types::Parameterizable qw(Parameterizable);

    subtype DecadeAlbum,
        as Parameterizable[Row['Album'], Str],
        where {
             my($album, $decade) = @_;
             return Row(['Album'])->check($album) && substr($album->year, -2, 1) eq substr($decade, 0, 1);
        };

    subtype EightiesRock,
        as DecadeAlbum[80],
        where { $_->genre eq 'Rock' };

    has eighties_rock_album => (
        is  => 'ro',
        isa => EightiesRock,
    );

DESCRIPTION

This simply provides some MooseX::Types style types for often shared DBIx::Class objects.

TYPES

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.

ResultSet[$source_name]

This type constraint requires the object to be an instance of DBIx::Class::ResultSet and to have the specified $source_name (if specified).

ResultSource[$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).

Row[$source_name]

This type constraint requires the object to be an instance of DBIx::Class::Row and to have the specified $source_name (if specified).

Schema[$class_name | qr/pattern_to_match/]

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.

BACKWARDS INCOMPATIBLE CHANGE

For any users of v0.02, you will need to replace all instances of use MooseX::Types::DBIx::Class::Parameterizable with MooseX::Types::DBIx::Class. The usage should be identical.

AUTHORS

  Oliver Charles <oliver@ocharles.org.uk>
  Brian Phillips <bphillips@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Brian Phillips.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.