Hi BrowserUk,
You are right in your assumptions. My::XML and My::JSON only provide data to the inherited class, no other methods are used (except methods internally used by My::XML or My::JSON).
If so, if you instantiated an instance of the relevant XML or JSON class to just parse the source data; then retrieved the data required by My class; and then allowed the parse instance to be reclaimed as soon as the initialisation of a new My class instance was complete; then your My class instances might be individually smaller. And possibly more efficien,t because of shorter method resolution paths.
Sorry if I misunderstand your. Are you suggesting the following?:
Package My:
sub new { my ($class,%args) = @_; my $data; if ($args{source} eq 'xml') { require My::XML; # @ISA = qw/My::XML/; $data = My::XML->new(%args); } elsif ($args{source} eq 'json') { require My::JSON; # @ISA = qw/My::JSON/; $data = My::JSON->new(%args); } my $self = bless \%{$data}, $class; return ($self); } # rest of methods sub method1 { ... } sub method2 { ... } 1;
Package My::XML
package My::XML; use XML::Simple qw(:strict); sub new { my ($class,%args) = @_; my $self = bless {}, $class; $self->_init(); return $self; } sub _init { # Code to read the data from XML source } 1;
Same for My::JSON
Thank you very much for your comments
citromatik
In reply to Re^2: Conditional inheritance strategy
by citromatik
in thread Conditional inheritance strategy
by citromatik
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |