in reply to Re: Encapsulation and Subroutine redefined warnings
in thread Encapsulation and Subroutine redefined warnings

qq,

Thanks for taking to time to provide that framework. That is what I was looking for to my overall design question. The one other question I have is about self determination of all the available processors. I planned on doing something similar to the following code, but I need to determine the base class versus just matching on the name of the object:
foreach $symname (sort keys %main::) { #print "$_\n" if /^ybcp/; if ( $symname =~ /^ybcp/ ) { local *sym = $main::{$symname}; $$sym->init(); #print "\$$symname\n" if defined $sym; } }
With loops like this in my driver script, I should be able to simply add a new use statement for new processors.

Also... Just to wrap up my thoughts on my original issue. I was confused by my Perl book's explanation of the Exporter implementation. I thought it was necessary to add methods to the Exporter to make them accessible, but I now realize that it meant accessible without the module:: syntax.

Replies are listed 'Best First'.
Re: Re: Re: Encapsulation and Subroutine redefined warnings
by qq (Hermit) on Nov 25, 2003 at 23:50 UTC

    If you want to loop over a list of subclassed processors, you probably want something like:

    use Processor; use Processor::SomeSubClass; use Processor::AnotherSubClass; foreach ( qw( SomeSubClass AnotherSubClass ) ) { my $pkg = "Processor::$_"; my $processor = $pkg->new(); $processor->init(); # do something with $processor }

    Damien Conway's book is very good on OO perl, although he skips fast past some of the simple stuff.

    qq