Catalyst-Controller-DBIC-API

 view release on metacpan or  search on metacpan

lib/Catalyst/Controller/DBIC/API/StoredResultSource.pm  view on Meta::CPAN

package Catalyst::Controller::DBIC::API::StoredResultSource;
$Catalyst::Controller::DBIC::API::StoredResultSource::VERSION = '2.009000';
#ABSTRACT: Provides accessors for static resources

use Moose::Role;
use MooseX::Types::Moose(':all');
use Catalyst::Controller::DBIC::API::Types(':all');
use Try::Tiny;
use namespace::autoclean;

requires '_application';


has 'class' => ( is => 'ro', isa => Str, writer => '_set_class' );


has 'result_class' => (
    is      => 'ro',
    isa     => Maybe [Str],
    default => 'DBIx::Class::ResultClass::HashRefInflator'
);


sub stored_result_source {
    return shift->stored_model->result_source;
}


sub stored_model {
    return $_[0]->_application->model( $_[0]->class );
}


sub check_has_column {
    my ( $self, $col ) = @_;
    die "Column '$col' does not exist in ResultSet '${\$self->class}'"
        unless $self->stored_result_source->has_column($col);
}


sub check_has_relation {
    my ( $self, $rel, $other, $nest, $static ) = @_;

    $nest ||= $self->stored_result_source;

    if ( HashRef->check($other) ) {
        my $rel_src = $nest->related_source($rel);
        die "Relation '$rel_src' does not exist" if not defined($rel_src);

        while ( my ( $k, $v ) = each %$other ) {
            $self->check_has_relation( $k, $v, $rel_src, $static );
        }
    }
    else {
        return 1 if $static && ArrayRef->check($other) && $other->[0] eq '*';
        die "Relation '$rel' does not exist in ${\$nest->from}"
            unless $nest->has_relationship($rel) || $nest->has_column($rel);
        return 1;
    }
}


sub check_column_relation {
    my ( $self, $col_rel, $static ) = @_;

    if ( HashRef->check($col_rel) ) {
        try {
            while ( my ( $k, $v ) = each %$col_rel ) {



( run in 2.412 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )