I am new to Moose and doing everything well until I get trapped using PDL as a property. I want to be able to write an object to a file (I used use MooseX::Storage; with Storage('io' => 'StorableFile');
and this object has a PDL
attribute as an attribute. PDL::IO::Storable
provides the necessary methods for using Storable
in this way, however, I donβt understand how to do this in the Muse.
Here is an example, it is a little long, I know, but it is as minimal as I can do it:
#!/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');
I think I might have to create a PDL type or even pack a PDL into something (using MooseX::NonMoose::InsideOut
), but maybe someone can save me from this (or point me on the right path , if so).
Joel berger
source share