Click here to get back home

Looking for a base module that can automatically load sub modules

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Looking for a base module that can automatically load sub modules xor 06-27-2007
Posted by xor on June 27, 2007, 6:16 am
Please log in for more thread options


Hi,

I am looking for a module, to make a base class module, that
automatically loads sub class modules.

Usually, to make a new Digest::MD5.pm module instance, you type

$inst = Digest::MD5->new(@args);

But, the Digest.pm module, let us type

$inst = Digest->MD5(@args);
$inst = Digest('MD5' => @args);

to do the same thing.

I want a module that can generate a module like Digest.pm.

I already made a module that can do it( let us call it
Class::AutoSubClass.pm), but there might be a similar module( but
scripted more elegantly ) in CPAN. Please tell me if there is.

The module I made( Class::AutoSubClass.pm )is below.

# Class/AutoSubClass.pm
package Class::AutoSubClass;

use strict;
use warnings;
use Carp;

sub new(@){
shift;
my $sBaseName = shift;
my $sName = shift;
my $rhDefaultDats = shift || {};
return bless $rhDefaultDats if !defined $sName or $sName eq '';
my $sClassName = $sBaseName.'::'.$sName;
eval "require $sClassName";
die if $@;
no strict 'refs';
return $sClassName->new(@_);
}
1; # end Class/AutoSubClass.pm

And you use it like this.

# Wiki/Handler.pm
package Wiki::Handler;

use strict;
use warnings;
use Carp;

use Class::AutoSubClass;

sub new(@){
shift;
return Class::AutoSubClass->new('Wiki::Handler',shift,@_);
}

1; # end Wiki/Handler.pm

By using this module, the new Wiki::Handler::HTMLFragment.pm object
can be generated like

$htmlf = Wiki::Handler->new('HTMLFragment');

Thanks.


Posted by Mark Clements on June 30, 2007, 8:58 am
Please log in for more thread options


xor wrote:
> Hi,
>
> I am looking for a module, to make a base class module, that
> automatically loads sub class modules.
>
> Usually, to make a new Digest::MD5.pm module instance, you type
>
> $inst = Digest::MD5->new(@args);
>
> But, the Digest.pm module, let us type
>
> $inst = Digest->MD5(@args);
> $inst = Digest('MD5' => @args);
>
<snip>
How about Module::Pluggable?

http://search.cpan.org/~simonw/Module-Pluggable-3.6/lib/Module/Pluggable.pm

Mark

Similar ThreadsPosted
Scary module base namespace proposal: Metaweb August 16, 2007, 5:51 pm
download Modules from CPAN and then load into Perl Question October 15, 2004, 3:07 pm
Unable to load module March 16, 2006, 12:00 am
Which module should I use in order to load files over the internet? October 5, 2006, 3:38 pm
lib/$archname not included automatically on RedHat box May 2, 2006, 9:26 pm
Win32::Service Determining which are set to start automatically July 12, 2004, 10:14 am
how to read email automatically without POP3 and IMAP servers in perl? December 13, 2004, 1:06 pm
Cant load ...BerkeleyDB.so for module BerkeleyDB: libdb-4.4.so January 19, 2006, 1:53 pm
Encode::Guess load ISO-8859-1 March 27, 2006, 10:09 am
UNIVERSAL::can function failing under heavy load August 25, 2005, 11:56 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap