尝试启动Catalyst服务器时出错

时间:2013-07-23 10:35:31

标签: perl catalyst

运行位于scripts/MyApp_server.pm的Catalyst内部服务器,收到以下错误。在这方面有没有人可以帮助我? 我没有更改catalyst.pl创建的任何文件。我刚刚运行了catalyst.pl MyApp,然后运行scripts / MyApp_server.pl -r来测试Catalyst是否有效。这是我做过的唯一事情! 我使用yum和cpan多次重新安装Catalyst及其依赖模块。但它不再起作用了。

谢谢!

错误消息:

Can't use an undefined value as a HASH reference at /usr/local/share/perl5/Catalyst.pm line 2681.
BEGIN failed--compilation aborted at /home/Ali/Lab/WEB/catalyst/MyApp3/script/../lib/MyApp3.pm line 20.
Compilation failed in require at /usr/local/lib/perl5/Class/MOP/Method/Wrapped.pm line 50

/usr/local/share/perl5/Catalyst.pm中第2681行附近的代码如下:

    sub setup_home {

        my ( $class, $home ) = @_;

        if ( my $env = Catalyst::Utils::env_value( $class, 'HOME' ) ) {
            $home = $env;
        }

        $home ||= Catalyst::Utils::home($class);
        if ($home) {
            #I remember recently being scolded for assigning config values like this
            $class->config->{home} ||= $home; # THIS IS LINE 2681
            $class->config->{root} ||= Path::Class::Dir->new($home)->subdir('root');
        }
    }

lib / MyApp.pm的内容如下:

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

use Catalyst::Runtime 5.80;

# Set flags and add plugins for the application
#
#         -Debug: activates the debug mode for very useful log messages
#   ConfigLoader: will load the configuration from a Config::General file in the
#                 application's home directory
# Static::Simple: will serve static files from the application's root
#                 directory

use Catalyst qw/
    -Debug
    ConfigLoader
    Static::Simple
/;

extends 'Catalyst';

our $VERSION = '0.01';
$VERSION = eval $VERSION;

# Configure the application.
#
# Note that settings in myapp.conf (or other external
# configuration file that you set up manually) take precedence
# over this when using ConfigLoader. Thus configuration
# details given here can function as a default configuration,
# with an external configuration file acting as an override for
# local deployment.

__PACKAGE__->config(
    name => 'MyApp',
    # Disable deprecated behavior needed by old applications
    disable_component_resolution_regex_fallback => 1,
);

# Start the application
__PACKAGE__->setup();


=head1 NAME

MyApp - Catalyst based application

=head1 SYNOPSIS

    script/myapp_server.pl

=head1 DESCRIPTION

[enter your description here]

=head1 SEE ALSO

L<MyApp::Controller::Root>, L<Catalyst>

=head1 AUTHOR

Ali Basirat

=head1 LICENSE

This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;

1 个答案:

答案 0 :(得分:3)

这不是一个明确的答案,但希望能有所帮助。

你有一个未定义的$class$class->config(更有可能),虽然我不能说。也许ConfigLoader没有用。

盲目地重新安装东西很少有帮助,问题可能是由于依赖项列表中的任何模块。如果在安装模块时遇到特定问题,那么就会出现错误,我们可以对此进行处理。

所以 - 使用yum install cpanmlocal::lib - 我不确定在Red Hat上调用哪些软件包,但它应该很容易找到。

好的 - 现在在适当的地方创建一个新目录。

mkdir /home/Devt/catalyst_test
cd /home/Devt/catalyst_test
eval $(perl -Mlocal::lib=./perllib)
echo $PERL5LIB
# You should see your current directory mentioned in PERL5LIB
cpanm Catalyst
cpanm Catalyst::Helper
catalyst.pl MyApp
cd MyApp/
perl Makefile.PL
./script/myapp_server.pl
# Opens up a server on port 3000

local :: lib正在做的是设置在本地安装所有内容的路径(在perllib中) - 你可以通过在没有eval的情况下运行它来查看它设​​置的环境变量。

perl -Mlocal::lib=./perllib

请参阅文档,了解如何将其添加到bash登录脚本中。我只是将输出重定向到一个文件,并在我处理项目时使用它(我每个项目使用一个perllib)。

然后,cpanm非常聪明,可以使用这个本地目录来安装你需要的所有位。

如果这不起作用,问题可能是由于你手动安装在/ usr / local /中的东西。 在/ usr / local /中对各种与perl相关的lib目录进行备份,然后将其清除。再次运行cpanm(首先设置local :: lib路径)并查看它下载的版本是否有效。

以上应该有效 - 这正是我10分钟前所做的。

这样做的全部意义是为这个项目创建所有perl库的单独安装 - 如果你升级它只会影响当前的安装。

相关问题