Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Module Naming Advice

by jk2addict (Chaplain)
on Feb 22, 2005 at 18:19 UTC ( #433439=perlquestion: print w/replies, xml ) Need Help??
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
    I would argue that you should see if you can have Data::UUID wrap itself around the appropriate Win32 modules. The patch shouldn't be too hard, I wouldn't think. I'd email that author and see what s/he says.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      Done. We'll see what comes out of that discussion.

      From the looks of it though, the XS stuff is way out of my league if it needs win32-ized, and merging in code from it's Win32 cousins that use CoCreateGuid().

Re: Module Naming Advice
by holli (Monsignor) on Feb 22, 2005 at 18:29 UTC
    If dragonchild's suggestion fails, iŽd go for UUID::Wrapper, as there are many XYZ::Wrapper-modules out there.

    holli, /regexed monk/
Re: Module Naming Advice
by brian_d_foy (Abbot) on Feb 22, 2005 at 21:08 UTC

    Rather than create a new module, I'd like to see the UUID modules merge and do the right thing. A lot off the time, authors are happy to do such a thing.

    Failing that, choose the module name you wish either of these modules had, but don't let on that it's a wrapper. The users of the module (as opposed to the people who will look under the hood) don't care if it's a wrapper: they care about what it does for them. Make it so they use the same interface no matter which backend they have to use.

    I don't think a generic wrapper to select different backends will be very useful for other situations. The logic and rules for selecting the modules will be too specialized, I think, and that's the part that does most of the work. People will want to program that part themselves to fit their situation.

    Good luck :)

    brian d foy <>
      I've talked to Alexander a little. Hopefully I can provide him enough debugging output to work on getting Data::UUID to build under win32.

      Here was my other motivation to wrapper this stuff: Class::DBI::UUID.

      I really wanted to use this in my modules that were already based on Class::DBI and used uuids as primary keys, but I couldn't because of the lack of Data::UUID compile on win32.

      I agree, ::Wrapper isn't the greatest. If I can come up with a decent name, maybe eventually it can move from acting like a wrapper to slowly including the necessary bits from all variations. That's assuming of course that Data::UUID can't be fixed easily.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://433439]
Approved by kvale
[choroba]: Perl programmers
[QM]: In Prague? A bit too far away for me.

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2017-06-29 10:17 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (658 votes). Check out past polls.