my $from_attr = $source_class->meta->find_attribute_by_name($attr_name);
my $reader = $from_attr->get_read_method;
+ die("Could not find reader for attribute '$attr_name' on $source_class")
+ unless $reader;
#default options. lazy build but no outsider method
my %attr_opts = ( is => 'ro', lazy => 1, required => 1,
} else {
#no rel
$attr_opts{isa} = $from_attr->_isa_metadata;
- $attr_opts{default} = eval "sub{ shift->${dm_name}->${reader} }";
+ my $default_code = "sub{ shift->${dm_name}->${reader} }";
+ $attr_opts{default} = eval $default_code;
+ die "Could not generate default for attribute, code '$default_code' did not compile with: $@" if $@;
}
return \%attr_opts;
};
sub get_collection {
my ($self, $c) = @_;
my $model = $c->model( $self->model_name );
+ confess "Failed to find Catalyst model named: " . $self->model_name
+ unless $model;
my $collection = $self->collection_name;
if( my $meth = $model->can( $collection ) ){
return $model->$meth;
- } elsif ( my $attr = $model->meta->find_attribute_by_name($collection) ) {
- my $reader = $attr->get_read_method;
- return $model->$reader;
+ } elsif ( my $meta = $model->can('meta') ){
+ if ( my $attr = $model->$meta->find_attribute_by_name($collection) ) {
+ my $reader = $attr->get_read_method;
+ return $model->$reader;
+ }
}
confess "Failed to find collection $collection";
}