0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Perlモジュールは最後に「1;」を書かないといけない

Posted at

Perlモジュールは最後に「1;」を書かないといけない

発生したエラー

Perlモジュール(.pm)を読み込もうとしたところ、以下のエラーが発生しました。
解決にだいぶ手こずりました。。。。

PostListHandler.pm did not return a true value at /usr/local/apache2/cgi-bin/post_list.cgi line 7.
BEGIN failed--compilation aborted at /usr/local/apache2/cgi-bin/post_list.cgi line 7.

エラーの原因

このエラーメッセージを分解すると

1行目: PostListHandler.pm did not return a true value

  • Perlモジュールは読み込み時に「真(true)の値」を返す必要がある
  • PostListHandler.pmが真の値を返していない

2行目: BEGIN failed--compilation aborted

  • コンパイル時(BEGIN phase)にエラーが発生
  • 7行目のモジュール読み込みで処理が中断された

エラー箇所の確認

CGIスクリプト(post_list.cgi)の該当部分

1: #!/usr/bin/perl
2: use strict;
3: use warnings;
4: # モジュール系
5: use lib '/usr/local/apache2/cgi-bin/module';
6: use BaseApp;
7: use PostListHandler;  # ← ここでエラー
8: use LogHandler;
9: use Constants;
10: use Data::Dumper;

解決方法

Perlモジュール(.pm)では、正常に読み込まれたことを示すため、最後に「1;(真値)」 を書く必要があるようです。
そのため、PostListHandler.pmの最後に以下を追加したところ、エラーが解消されました。

# PostListHandler.pm
1;  # ← これを最後に追加
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?