Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Namespace for local/internal modules?

by Anonymous Monk
on May 23, 2012 at 22:42 UTC ( [id://972123]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is there a module namespace that I can use so that it's guaranteed not to conflict with CPAN modules? I have a bunch of internal modules under the Math:: namespace with generic names like "Math::GaussianProcess" that's sooner-or-later bound to interfere with a CPAN author wanting to implement the same thing. I remember reading somewhere long ago that the "Local::*" was meant for this purpose, but a search of CPAN shows that there are modules in this namespace...

Replies are listed 'Best First'.
Re: Namespace for local/internal modules?
by tobyink (Canon) on May 23, 2012 at 22:50 UTC

    Indeed, Local:: is the namespace you should use for local things. There are a handful of modules in this namespace if you search CPAN, but if you look closely they're mostly in "examples" directories, not in "lib", so will usually not get installed.

    local::lib and some of its friends are unfortunate. Technically they're not violating the rule, but on case-insensitive filesystems they might as well be.

    If you have a CPAN ID yourself, you can always use your own CPAN ID (in all caps) as a namespace. Many people regard that as a namespace that 100% belongs to the owner of the CPAN ID. That is, I could release a module called TOBYINK::Monkey, but for anyone else to do so would be outrageous.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
      Thanks for the clarification about Local::. And I did not know about using CPAN ID's as top level namespaces. That seems more ideal since others can get at it. (One of the reasons I haven't released some of my better modules is that, especially for mathematical modules, there's no good name other than the thing being implemented like "Math::CholeskyDecomposition" or whatever, but there are multiple ways of doing math in perl (Math::GSL, PDL, Math::Matrix, straight vanilla perl, etc), so I don't want to usurp the namespace.)

      "If you have a CPAN ID yourself, you can always use your own CPAN ID (in all caps) as a namespace." -- tobyink.

      Blech! Aesthetic reasons alone are too strong for me then not to use "Local" instead.

      Technically they're not violating the rule

      There is no such rule

        s/rule/strong convention/
        perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re: Namespace for local/internal modules?
by Anonymous Monk on May 24, 2012 at 09:35 UTC
    perlmodlib says
    If developing modules for private internal or project specific use, that will never be released to the public, then you should ensure that their names will not clash with any future public module. You can do this either by using the reserved Local::* category or by using a category name that includes an underscore like Foo_Corp::*.
Re: Namespace for local/internal modules?
by chrestomanci (Priest) on May 25, 2012 at 09:32 UTC

    Similar to the idea of using you CPAN id, you could also use your company name as the root of your namespace. Most of companies I have worked for in the past five years have done that, and it works fairly well.

    Obviously if you work for a massive corporation you many find that your have replaced clashes at the root of the namespace with clashes at the next level down, where your version of <company>::Math conflicts with another team half a continet away.

    The other issue would be if you work for an internet company where the public are creating both authorised an un-authorised API interfaces to your publicly facing systems, so if you work for Google, then it would probably not be a good idea to use that as a namespace root, and you will conflict with other people creating Google APIs.

      reverse it, Local::elgooG::Brownies

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://972123]
Approved by tobyink
Front-paged by tobyink
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-03-28 21:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found