| 1 | package Reaction::UI::Controller::Role::GetCollection; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 4 | ▶ | use Moose::Role -traits => 'MethodAttributes'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | 4 | has model_name => (isa => 'Str', is => 'rw', required => 1); | |||||||||||||
| 6 | 4 | has collection_name => (isa => 'Str', is => 'rw', required => 1); | |||||||||||||
| 7 | |||||||||||||||
| 8 | 3 | ▶ | sub get_collection { | ||||||||||||
|
Subroutine
get_collection: called CC=5 SCAR=17.8
Pod
documented
| |||||||||||||||
| 9 | 3 | my ($self, $c) = @_; | |||||||||||||
| 10 | 3 | my $model = $c->model( $self->model_name ); | |||||||||||||
| 11 | 3 | ▶ | confess "Failed to find Catalyst model named: " . $self->model_name | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 12 | unless $model; | ||||||||||||||
| 13 | 3 | my $collection = $self->collection_name; | |||||||||||||
| 14 | 3 | ▶ | if( my $meth = $model->can( $collection ) ){ | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 15 | 0 | return $model->$meth; | |||||||||||||
| 16 | } elsif ( my $meta = $model->can('meta') ){ | ||||||||||||||
| 17 | 3 | ▶ | if ( my $attr = $model->$meta->find_attribute_by_name($collection) ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 18 | 3 | my $reader = $attr->get_read_method; | |||||||||||||
| 19 | 3 | return $model->$reader; | |||||||||||||
| 20 | } | ||||||||||||||
| 21 | } | ||||||||||||||
| 22 | 0 | confess "Failed to find collection $collection"; | |||||||||||||
| 23 | } | ||||||||||||||
| 24 | |||||||||||||||
| 25 | 4 | 1; | |||||||||||||
| 26 | |||||||||||||||
| 27 | __END__; | ||||||||||||||