jk2addict has asked for the wisdom of the Perl Monks concerning the following question:
Here's the nugget in the back on my brainpan today. I'm working on a project in which I need to create uuid/guid strings.
This currently involves some Makefile.PL and module hackery jiggery pokery because some uuid modules don't compile on windows, and some don't work on non windows. All code quality aside, this roughly equates to:
## Makefile.PL : PREREQ_PM if ($^O eq 'MSWin32') { eval 'use UUID 0.02;'; eval 'use Win32::Guidgen 0.02;' if $@; eval 'use Win32API::GUID 0.02;' if $@; %modules = ('UUID' => 0.02) if $@; } else { %modules = ('Data::UUID' => 0.10); }; ## module code sub uuid { my $uuidstring; if (eval{require UUID}) { my $uuid; UUID::generate($uuid); UUID::unparse($uuid, $uuidstring); } elsif (eval{require Data::UUID}) { my $ug = Data::UUID->new; my $uuid = $ug->create; $uuidstring = $ug->to_string($uuid); } elsif (eval{ # for some reason 'no warnings' won't squelch # the 'too late for INIT' warning in Win32::API::Type local $^W = 0; require Win32::Guidgen; }) { $uuidstring = Win32::Guidgen::create(); } elsif (eval{require Win32API::GUID}) { $uuidstring = Win32API::GUID::CreateGuid(); } else { throw Handel::Exception( -text => 'Required modules not found', -details => 'UUID/Data::UUID' ); }; return $uuidstring; };
As part of the refactoring process, I'd like to move all of this into a seperate module that Does The Right thing based on what is installed, and then only one module is needed in PREQ_PM.
Maybe I'm reading to much into it, but I think such a module that would abstract out which uuid core is being used might be useful to others on CPAN. As usual, the code is easy, but I'm having a hard time coming up with an appropriate module namespace/name for said module.
Any suggestions? Is it even worth it to others to have such a generic wrapper?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Module Naming Advice
by dragonchild (Archbishop) on Feb 22, 2005 at 18:23 UTC | |
by jk2addict (Chaplain) on Feb 22, 2005 at 18:37 UTC | |
Re: Module Naming Advice
by holli (Abbot) on Feb 22, 2005 at 18:29 UTC | |
Re: Module Naming Advice
by brian_d_foy (Abbot) on Feb 22, 2005 at 21:08 UTC | |
by jk2addict (Chaplain) on Feb 22, 2005 at 21:32 UTC | |
by jk2addict (Chaplain) on Feb 24, 2005 at 20:28 UTC |