Hi,
I have troubles using a subclass of PDL and exporting PDL as well as my
own functions. If I uncomment the Exporter line, I get myfunc() alright,
but not the PDL namespace. Is there a way to get both?
Ingo
#!/usr/bin/perl
package pdl_subclass;
use strict;
use 5.10.0;
use base 'PDL';
use PDL;
$pdl_subclass::ISA = qw/PDL/;
use Storable qw(dclone);
use PDL::Exporter;
#use Exporter qw/import/;
our @EXPORT=qw/myfunc/;
sub new {
my $class = shift;
say "Hello! $class";
my $data = $_[0];
say $data;
my $self;
if(ref($data) eq 'PDL' ){ # if $data is an object (a pdl)
$self = $class->initialize;
$self->{PDL} = $data;
}
else{ # if $data not an object call inherited constructor
$self = $class->SUPER::new($data);
}
return $self;
}
####### Initialize function. This over-ridden function is called by the
PDL constructors
sub initialize {
my $class = shift;
my $self = {
PDL => PDL->null, # used to store PDL object
someThingElse => 42,
};
$class = (ref $class ? ref $class : $class );
bless $self, $class;
}
###### Derived Object Needs to supply its own copy #####
sub copy {
my $self = shift;
# setup the object
my $new = $self->initialize;
$new=dclone($self);
# copy the PDL
$new->{PDL} = $self->{PDL}->SUPER::copy;
# copy the other stuff:
return $new;
}
sub myfunc {
"Hello world!";
}
1;
__END__
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
pdl-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdl-devel