一個木對象。我希望能夠到一個對象寫入(我一直在使用use MooseX::Storage; with Storage('io' => 'StorableFile');
一個文件,這個對象有一個PDL
的屬性。PDL::IO::Storable
提供必要的方法,以這種方式使用Storable
,但我在一個頭緒要做到這一點在穆斯商店具有PDL,因爲我是新來的駝鹿和做得相當不錯,直到我擊中使用PDL作爲屬性碰釘子屬性
下面是一個例子,這是一個有點長,我知道,但它是最小的,因爲我可以把它:
#!/usr/bin/perl
package LinearPDL;
use Moose;
use PDL::Lite;
use PDL::IO::Storable;
use MooseX::Storage;
with Storage('io' => 'StorableFile');
has 'length' => (is => 'ro', isa => 'Num', required => 1);
has 'divisions' => (is => 'ro', isa => 'Int', required => 1);
has 'linear_pdl' => (is => 'ro', isa => 'PDL', lazy => 1, builder => '_build_pdl');
sub _build_pdl {
my $self = shift;
my $pdl = $self->length()/($self->divisions() - 1) * PDL::Basic::xvals($self->divisions());
return $pdl;
}
no Moose;
__PACKAGE__->meta->make_immutable;
use strict;
use warnings;
my $linear_pdl = LinearPDL->new('length' => 5, 'divisions' => 10);
print $linear_pdl->linear_pdl;
$linear_pdl->store('file'); # blows up here!
my $loaded_lpdl = load('file');
print $loaded_lpdl->linear_pdl;
我想我可能要做出一個PDL型或甚至包裹PDL到的東西(使用MooseX::NonMoose::InsideOut
),但也許有人能救我從(或點我沿着正確的道路,如果它是)。
這看起來很有希望,你可以擴大一點嗎?我是否在類定義中創建'$ engine'對象?擴展和崩潰的輸入和輸出是什麼?有沒有更好的文檔或教程可以找到的地方?謝謝! – 2011-05-23 23:50:16
Joel不幸的是這是MooseX :: Storage的記錄不足部分。這就是爲什麼我建議與irc頻道和/或名單談話。我早些時候對MooseX :: Storage做了一個快速瀏覽[源文件](http://cpansearch.perl.org/src/BOBTFISH/MooseX-Storage-0.30/lib/MooseX/Storage/Engine.pm),因爲我知道此功能存在,但不記得如何/在哪裏。 – perigrin 2011-05-24 02:06:34
然後我發佈最後的評論,然後意識到我可以看看測試套件,發現[示例](http://cpansearch.perl.org/src/BOBTFISH/MooseX-Storage-0.30/t/006_w_custom_type_handlers.t)正是你想要的。 – perigrin 2011-05-24 02:11:30