Catalyst-ActionRole-BuildDBICResult

 view release on metacpan or  search on metacpan

lib/Catalyst/ActionRole/BuildDBICResult.pm  view on Meta::CPAN

package Catalyst::ActionRole::BuildDBICResult;

our $VERSION = '0.04';

use Moose::Role;
use namespace::autoclean;
use Try::Tiny qw(try catch);
use Perl6::Junction qw(any all);
use Catalyst::ActionRole::BuildDBICResult::Types qw(:all);

requires 'name', 'dispatch', 'attributes';

has 'store' => (
    isa => StoreType,
    is => 'ro',
    coerce => 1,
    lazy_build => 1,
);

sub _search_attributes_for {
    my ($self, $attr) = @_;
    my $attribute = $self->attributes->{$attr} || $self->attributes->{lc $attr};
    if ($attribute) {
        my ($value, @more) = @{$attribute};
        return @more ? [$value, @more] : $value;
    } else {
    return;
    }
}

sub _build_store {
    my $self = shift @_;
    if(my $store = $self->_search_attributes_for('Store')) {
        my ($value, @extra) =  eval $store || eval '"$store"';
        if(@extra) {
            return {$value, @extra};
        } else {
            return $value;
        }
    } else {
        return +{accessor=>'model_resultset'}
    }
}

has 'find_condition' => (
    isa => FindConditions,
    is => 'ro',
    coerce => 1,
    lazy_build => 1,
);

sub _build_find_condition {
    my $self = shift @_;
    if(my $fc = $self->_search_attributes_for('Find_condition')) {
        my ($value, @extra) =  eval $fc || eval '"$fc"';
        if(@extra) {
            return [$value, @extra];
        } else {
            return $value;
        }
    } else {
        return  +[{constraint_name=>'primary'}] 
    }
}

has 'auto_stash' => (is=>'ro', isa=>AutoStash, lazy_build=>1);



( run in 1.192 second using v1.01-cache-2.11-cpan-39bf76dae61 )