Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.
I was going to release a module named "Aliased" which would alias long class names to short ones. However, it's only for OO modules , it sort of alters compile-time behavior so one might think of it as a pragma, and "class" is not a keyword. Thus, I could do this:
use class 'My::Company::Namespace::Customer';
use class 'My::Company::Namespace::Preferred::Customer', as => 'Preferred';
my $cust = Customer->new;
my $pref = Preferred->new;
My immediate reaction was "no!", we don't want to do that. Then I realized I couldn't think of a reason why. Can you? I certainly don't want to release that and make people mad (though Theory pointed out that "class" doesn't indicate that anything's getting exported to the current namespace).
Side note: the "as" key in the import list is important because there's a separate "import" key in case you need to pass args to the module's import() method.
Like It (Score:1)
That's an excellent idea! Now when people submitting requests to modules@perl.org complain that they want their pet module to have a short name cos it saves typing in their programs (at the expense of being meaningful in the global hierarchy) this can provide a solution.
It's also handy when a module changes its name — just change the
useline, and leave other references to the class alone.Re:Like It (Score:1)
Re:Like It (Score:1)
From the the point of view of having an official list of registered modules, quite possibly. But the process definitely is useful in moderating modules' names.
brian d foyin particular is good at spotting when a module has been submitted with an awkward name and suggesting a better one, and in general the suggestions are acted upon. That makes Cpan a more pleasant place for all of us.Smylers
Perl or Java? (Score:2)
On the other hand, it's Java all over again. Every time I look at a Java program, I see statements like import java.io.* and the like. A few lines later, I see references to classes I've never seen before from one package or another, and I don't know where to go when I'm looking up methods on some interface like XMLReader or some class like HashMap. Because the package prefixes are stripped, I've lost all co
Re:Perl or Java? (Score:2)
This is somewhat different from the Java model (I had considered implementing that but I abandoned the idea as causing more problems than it solved [perlmonks.org]). Java is frustrating because, as you point out, you can silently bring in tons of namespaces and not know their origin. However, class.pm does this one module at a time. You can always glance at the code at the top of the package to see where the package comes from.
How would it work? (Score:1)
So... what would it do if you had not used 'as => 'Preferred' in the second instance?
It looks like it is "aliasing" the module name (the last part) but that is the same as the previous module... so would it re-alias Customer?
And... does it alias all modules that are used after calling it? I think I'd really, really
Re:How would it work? (Score:2)
It only aliases what you tell it to alias, so no worries there. Also, the entire point of this is to keep things really, really simple. Dirt simple. Making it all OO defeats that. All this module really does (mostly) is to use the package in question and then insert a sub into your namespace that returns the name of the module.
perl 6 (Score:2)
Obviously "don't use that name, because someone else might" could be said of any name, but I think a potentially very popular name like 'class' might be worth extra caution.
Then again, if you call it 'class', someone who hates the name can write a thin wrapper calling it what
Re:perl 6 (Score:2)
Hi Matt. I'm going to call it "aka.pm" because it's short and that's a name that received fairly decent support on the module author's list. I was also hesitant about the Perl 6 issue, oddly enough. I'll probably have it uploaded in the next day or two unless there's some strenous objection from the PAUSE admins.
please, no (Score:1)
Re:please, no (Score:2)
I fear that you are in the minority. Though many have objected to the name -- leading me to change it -- you're the only person who has objected to the idea of the module.
The inspiration for this code was a module named "Aliased" that Rentrak [rentrak.com] uses extensively in their code. (They have graciously allowed me to duplicate the functionality of the code.) The reason I mention this is because while the code is new, the interface is not and it has withstood the test of time for very large scale systems (enterp
Re:please, no (Score:1)
Re:please, yes (Score:2)
Yes, I did misunderstand you. However, even though there are a couple of people who objected to the interface, I fear you're still in the minority. As I mentioned previously, I and a number of other programmers have been using a virtually identical interface for so long without any problems (and with strong benefits) that I'm still quite comfortable with the interface.
You are someone who I generally pay extra attention to given my respect for your abilities. In this case, I must disagree due to extens
Re:please, no (Score:2)
But I see that your clarification, and yes, the abuse of the import list is quite horrid.
Perl is a dynamic language. There's no reason why the magic fiddling must happen at compile time, nor is there any reason why it the aliasing must use a use sta
Re:please, no (Score:2)
Well, my thought is pretty straight-forward: the current code I have implemented not only works, it fits very naturally with current Perl syntax. I can't say that I like the syntax of how I handled importing, but that's not the common case. The important thing is that the common case be handled easily. The more programming people do, the more they want the common things to be short-n-sweet.
My code is ready to be uploaded and I'm merely waiting for last minute objections from the modules@cpan.or
Re:please, no (Score:1)
As well you should. The right code is even shorter and clearer.
Re:please, no (Score:2)
Silly me. For some stupid reason I thought I shouldn't use $package->can('import') because there's no guarantee that there's an import method. Mentally I thought "there's no guarantee that package can('can') and that might throw an error." It's weird how muddled my mind substituted "can" for "import" in that method call :/
Re:please, no (Score:1)
Good idea, bad name (Score:2)
Don't see the point. (Score:1)
Why does this need an entire module?
I've used this not-even-a-trick on several occasions, FWIW.
Note how it makes no difference in the actual code, just makes effective use of what's already in the core. (And you could even do without
constant.pmusing prototyped subs, but that is too opaque for my tas