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

NAME

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

VERSION

version 0.02

SYNOPSIS

    # in your Moose class
    use MooseX::Types::DBIx::Class::Parameterizable qw(ResultSet Row);

    # this attribute must be a DBIx::Class::Row object from your "Album" Result class
    has album => (
        is  => 'ro',
        isa => Row['Album']
    );

    # this attribute must be a DBIx::Class::ResultSet object from your "Album" ResultSet class
    has other_albums => (
        is  => 'ro',
        isa => ResultSet['Album']
    );

    # for convenience, these types can act like their non-parameterized base types too
    has any_resultset => (
        is  => 'ro',
        isa => ResultSet
    );

    # 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;
    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 module provides parameterizable versions of the same types provided by MooseX::Types::DBIx::Class.

TYPES

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.

AUTHOR

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

COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Oliver Charles.

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