6
########### Test of Subclassed-object copying for simple function cases ###########
9
## First define a PDL-derived object:
11
@PDL::Derived::ISA = qw/PDL/;
20
if(ref($data) eq 'PDL' ){ # if $data is an object (a pdl)
21
$self = $class->initialize;
24
else{ # if $data not an object call inherited constructor
25
$self = $class->SUPER::new($data);
31
####### Initialize function. This over-ridden function is called by the PDL constructors
35
PDL => PDL->null, # used to store PDL object
38
$class = (ref $class ? ref $class : $class );
42
###### Derived Object Needs to supply its own copy #####
47
my $new = $self->initialize;
50
$new->{PDL} = $self->{PDL}->SUPER::copy;
52
# copy the other stuff:
53
$new->{someThingElse} = $self->{someThingElse};
60
#######################################################
63
###### Testing Begins #########
68
# Create New PDL::Derived Object
69
# (Initialize sets 'someThingElse' data member
71
$im = new PDL::Derived [
79
# Set 'someThingElse' Data Member to 24. (from 42)
80
$im->{someThingElse} = 24;
82
# Test to see if simple functions (a functions
83
# with signature sqrt a(), [o]b() ) copies subclassed object correctly.
84
my @simpleFuncs = (qw/
85
bitnot sqrt abs sin cos not exp log10 /);
87
foreach my $op( @simpleFuncs){
91
ok($testNo++, $w->{someThingElse} == 24 );
99
print "not " unless $result ;