Hello Ingo,

I have a few comments. First, your module will only export functions
explicitly listed in the @EXPORT and @EXPORT_OK lists. These do not get
inherited from parent classes, for better or worse. Second, it looks like
you're assigning to pdl_subclass's $ISA, not @ISA. The array form is what
you're looking for. (Does this inheritance scheme actually do what you
expect?) Finally, PDL::Exporter is a copy of Exporter that defaults to
anything labeled :Func in %EXPORT_TAGS, as opposed to anything under
@EXPORT. I have found that PDL's Exporter does not really give me anything
over the normal Exporter, and tend to just work with the latter.

Hope that helps!
David

On Wed, Nov 2, 2016 at 12:26 PM, Ingo Schmid <ingo...@gmx.at> wrote:

> PS: here is the main program.
>
>
> use pdl_subclass ; # qw/myfunc/;
> use 5.10.0;
>
> say "A ",myfunc();
> say ones(10);
>
>
>
> On 11/02/2016 05:23 PM, Ingo Schmid wrote:
> > 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
> > pdl-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/pdl-devel
>
>
>
> ------------------------------------------------------------
> ------------------
> 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
> pdl-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pdl-devel
>



-- 
 "Debugging is twice as hard as writing the code in the first place.
  Therefore, if you write the code as cleverly as possible, you are,
  by definition, not smart enough to debug it." -- Brian Kernighan
------------------------------------------------------------------------------
_______________________________________________
pdl-devel mailing list
pdl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pdl-devel

Reply via email to