Perl 模块“未返回真值”
我遵循了 CPAN 上的 Rose::DB::Object 教程并设置三个包。
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');
在应用程序中:
package main;
use Motorcycle;
use Mojolicious::Lite;
无法编译并出现此错误:
My/DB/Object did not return a true value <eval 2> line 2…
问候和感谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然我不能说我完全理解您想要完成的任务,但您看到的错误是一个相当常见的错误。
use
或require
中包含的任何文件/模块都必须返回“true”值。这通常是通过以1;
行结束该文件来完成的,也就是说,只是一个 true 的命令(而不是 0 为 false)。查看系统上以 .pm 结尾的任何其他文件,它很可能会以这种方式结束。还可以在
perldoc perlmod
中阅读更多内容,或者有这样的说法来自perldoc -f require
: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
orrequire
must return a "true" value. This is usually accomplished by ending that file with the line1;
, 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 fromperldoc -f require
:任何模块中的最后一行应该是
The last line in any module should be