in reply to Re: use, require, and constructors (factories++)
in thread use, require, and constructors
It would be nice if require and/or use would return a factory (by default, just the class name).Problem with that is that other people are (ab)using require's return value for other things. Unless you just meant having require cache the true return value the first time and return it every time.
If the module exports any subs, you can get the package name from them:
(as long as the module didn't itself import the sub from elsewhere).$ cat Foo.pm package Foo; use strict; use warnings; use base "Exporter"; our @EXPORT = "bar"; sub bar { "baz" } 1; $ perl -we'use Foo; use B; print B::svref_2object(\&bar)->STASH->NAME' Foo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: use, require, and constructors (factories++)
by tye (Sage) on Oct 27, 2004 at 15:25 UTC | |
by ysth (Canon) on Oct 27, 2004 at 17:53 UTC |