Search code examples
perlcatalyst

Why am I getting this error with the perl module Catalyst::Model::Adaptor?


I'm trying to get an old project I was handed to run and I'm running into a problem with the model we have for TheSchwartz. The code looks exactly the same as a bunch of other examples to do similar things I've found online. The code is also pretty simple;

package MyApp::Model::TheSchwartz;
use Moose;
use namespace::autoclean;

extends 'Catalyst::Model::Adaptor';

__PACKAGE__->config( class => "TheSchwartz" );

sub mangle_arguments
{
  my ($self, $args) = @_;
  if($args->{databases})
  {
    if(ref($args->{databases}) eq 'HASH')
    {
      my %db = %{ $args->{databases} };
      $args->{databases} = [ \%db ];
    }
  }
  return %{ $args }
}
1;

The error I get is

Couldn't instantiate component "MyApp::Model::TheSchwartz", "unknown options args, catalyst_component_name, class at /usr/local/share/perl/5.14.2/Catalyst/Model/Adaptor/Base.pm line 27."Compilation failed in require at /usr/local/share/perl/5.14.2/Module/Runtime.pm line 317.
 at /usr/local/share/perl/5.14.2/Catalyst/Script/Server.pm line 242.

I've tried removing the mangle_arguments function, I've tried removing the Moose usage and using "use base" instead. I always end up with the same error, and I'm really having a hard time even grokking the error message. I don't see catalyst_component_name defined anywhere in my code so it must be passed down from Catalyst::Model::Adaptor, but.. why doesnt it work?

EDIT:

here's the relevant config section:

<Model::TheSchwartz>
    <args>
        verbose 1
        <databases>
            dsn     dbi:mysql:host=db.vpn;dbname=theschwartz
            user    user
            pass    password
        </databases>
    </args>
</Model::TheSchwartz>

Solution

  • This is downright silly and one of those things you try just to say you tried it without expecting it to work, but somehow this actually seems to have fixed it.

    delete $args->{class};
    delete $args->{catalyst_component_name};
    delete $args->{args};
    return %{ $args }
    

    The model still seems to work properly, though I really expect to have broken something by just arbitrarily deleting the keys that were erroring like that.