別のオブジェクトグループの配列の属性を持つ1つのオブジェクトがあります。オブジェクトの内容全体を出力したいtoStringメソッドがあります。主な目標は、Jobオブジェクトが配列内にあるすべての後処理ジョブを呼び出すようにすることです。オブジェクト配列内のオブジェクトに対してもメソッドtoStringを呼び出したいと思います。現在、次のエラーが発生しています。
Can't call method "toString" without a package or object reference at JobClass.pm line 52, <JOBFILE> line 5. (which is $item->toString(); in the foreach loop)
$ itemのダンパーは、次のことを示しています。
$VAR1 = bless( {
'ImportID' => '22',
'ImportTableID' => '1234',
'ImportTable' => 'testImport'
}, 'PostJob' );
私が理解しようとしていることの主な目標は、メンバー配列から返されたオブジェクトのメソッドを呼び出す方法です。
クラスは次のようにインスタンス化されます。
my $ postJob = PostJob-> new(ImportTable => "testImport"、ImportTableID => "1234"、ImportID => "22");
私の@postJobs="";
プッシュ(@ postJobs、$ postJob);
$ postJob-> toString(); #これは正常に機能します
my $ job = Job-> new(DirectoryName => "testDir"、StagingTableName => "stageTable"、QBStagingTableID => "5678"、postProcessJobs => \ @postJobs);
$ job-> toString(); #上記のエラーのあるブレーク
コードは以下のとおりです。
パッケージPostJob;
Mooseを使用します。
厳密に使用します。
Data::Dumperを使用します。
'ImportTable' =>(isa =>'Str'、is =>'rw'、required => 1);
'ImportTableID' =>(isa =>'Str'、is =>'rw'、required => 1);
'ImportID' =>(isa =>'Str'、is =>'rw'、required => 1);
sub toString {
#すべての値を出力
私の$self=シフト;;
print"ポストジョブのテーブル名は"。$self->ImportTable。"\n";
print"ポストジョブのテーブルIDは"。$self->ImportTableID。"\n";
print"ポストジョブのインポートIDは"。$self->ImportID。"\n";
}
パッケージジョブ;
厳密に使用します。
Data::Dumperを使用します。
Mooseを使用します。
'DirectoryName' =>(isa =>'Str'、is =>'rw'、required => 1);
'StagingTableName' =>(isa =>'Str'、is =>'rw'、required => 1);
'StagingTableID' =>(isa =>'Str'、is =>'rw'、required => 1);
'postProcessJobs' =>(isa =>'ArrayRef'、is =>'rw'、required => 0);
sub addPostJob {
my($ self、$ postJob)= @_;
push(@ {$ self-> postProcessJobs()}、$ postJob);
}
sub toString
{{
#すべての値を出力します。
私の$self=シフト;
print "DUMPING JOB OBJECT CONTENTS ***************************** \ n";
print"ディレクトリは"。$self->DirectoryName。"\n";
print"ステージングテーブルは"。$self->StagingTableName。"\n";
print"ステージングテーブルIDは"。$self->StagingTableID。"\n";
print "DUMPING POST JOB CONTENTS ***************************** \ n";
foreach my $ item(@ {$ self-> postProcessJobs()})
{{
$ item-> toString();
Dumper($ item);を印刷します。
}
print "END DUMPING JOBS ***************************** \ n";
}
1;