Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl module "did not return a true value"

I followed the Rose::DB::Object tutorial on CPAN and set up three packages.

package My::DB::Object;
use My::DB;
use base qw(Rose::DB::Object);
sub init_db { My::DB->new }

package My::DB;
use base qw(Rose::DB);
...

package Motorcycle;
use base 'My::DB::Object';

__PACKAGE__->meta->setup
(
  ...
);

__PACKAGE__->meta->make_manager_class('motorcycles');

In the application:

package main;

use Motorcycle;
use Mojolicious::Lite;

This failed to compile with this error:

My/DB/Object did not return a true value <eval 2> line 2…

Regards and thanks.

like image 291
Weiyan Avatar asked Feb 16 '11 05:02

Weiyan


1 Answers

While I can't say I fully understand what it is you are trying to accomplish, the error you are seeing is a fairly common one. Any file/module that is included with a use or require must return a "true" value. This is usually accomplished by ending that file with the line 1;, that is to say simply a command that is true (as opposed to 0 being false). Look at any other file ending in .pm on your system and it is likely to end this way.

You can also read more in perldoc perlmod, or there is this statement from perldoc -f require:

The file must return true as the last statement to indicate successful execution of any initialization code, so it's customary to end such a file with "1;" unless you're sure it'll return true otherwise. But it's better just to put the "1;", in case you add more statements.

like image 189
Joel Berger Avatar answered Sep 19 '22 08:09

Joel Berger