Subject: | Broken Schema::Loader args with "sub { }" in Catalyst::Helper::Model::DBIC::Schema; |
When feed code ref to loader args such as
project_create.pl ........ inflect_singular="sub { $_[0] =~
/\A(.+?)(_id)?\z/; $1 }" moniker_map="sub { return join('', map ucfirst,
split(/[\W_]+/, lc $table));"
I get exception
syntax error for loader args key 'moniker_map' with value
'ARRAY(0x35a74c4)': Undefined subroutine
&Catalyst::Helper::Model::DBIC::Schema::ARRAY called at (
eval 258) line 1.
Reason:
_read_loader_args calls $self->_is_struct($val) on Line 279 but
_is_struct tries to test it with return $val =~ /^\s*[[{]/;
In above example inflect_singular option falls into else part in
_read_loader_args and works, on the other hand moniker_map fals into
elsif trying to evaluated as array which fails.
This may solve the problem:
return $val =~ /^\s*(sub|[[{])/;