Perl module "did not return true value"

I followed Rose :: DB :: Object tutorial in CPAN and configured 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 could not be compiled with this error:

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

With respect and gratitude.

+4
source share
3 answers

So far I can’t say that I fully understand what you are trying to accomplish, the error you see is quite common. Any file / module that is included in use or require must return true. This usually ends with the completion of this file with line 1; , i.e. Just a command that is true (as opposed to 0 - false). Look at any other file ending with .pm on your system, and most likely it will end.

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

The file should return true as the last one to confirm the successful execution of any initialization code, therefore, such a file usually ends with "1;" if you are not sure it will return true otherwise. But it’s better to just put “1;”, in case you add more statements.

+19
source

The last line in any module should be

 1; 
+6
source

Note: a perldoc comment may interfere with the caller from -reading-.pm - even with a ending of 1;

Delete the comment block - oila. Add it - the program did not return the true value.

1; remains the same!

-1
source

Source: https://habr.com/ru/post/1339940/


All Articles