You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by George Sanderson <ge...@xorgate.com> on 2001/10/12 00:15:32 UTC
[OT] Overridding a module's use of a function
I discovered that File::NCopy uses the function "glob" to expand file
names. My problem is that I need to pass file names that have spaces in
them and "glob" does not process them. So I did the following override (I
do not need to expand the file names):
package Apache::AAM;
. . .
package File::NCopy;
use subs qw(glob);
sub glob {@_};
package Apache::AAM;
. . .
Is there a better way to do this?
+================================+
| George Sanderson <ge...@xorgate.com>
| http://www.xorgate.com
+================================+
Re: [OT] Overridding a module's use of a function
Posted by Robert Landrum <rl...@capitoladvantage.com>.
At 5:15 PM -0500 10/11/01, George Sanderson wrote:
>I discovered that File::NCopy uses the function "glob" to expand file
>names. My problem is that I need to pass file names that have spaces in
>them and "glob" does not process them. So I did the following override (I
>do not need to expand the file names):
>
>package Apache::AAM;
>. . .
>package File::NCopy;
>use subs qw(glob);
>sub glob {@_};
>package Apache::AAM;
>. . .
*File::NCopy::glob = sub {@_}; # should do the same thing
I think _Advanced Perl Programming_ covered overriding subs with subrefs...
Rob
--
"Only two things are infinite: The universe, and human stupidity. And I'm not
sure about the former." --Albert Einstein
Re: [OT] Overridding a module's use of a function
Posted by Drew Taylor <dr...@drewtaylor.com>.
It's funny you should ask, because I just finished reading that section
today! :-) On pg 306-7 of the Camel (3rd edition):
*CORE::GLOBAL::glob = sub {
my $pat = shift;
my @got;
# do whatever
return @got;
}
will override a built-in function everywhere, regardless of namespaces. The
method you use (namely overriding CORE::function) restricts the overriding
of the function "to the package that requests the import."
At 05:15 PM 10/11/01 -0500, George Sanderson wrote:
>I discovered that File::NCopy uses the function "glob" to expand file
>names. My problem is that I need to pass file names that have spaces in
>them and "glob" does not process them. So I did the following override (I
>do not need to expand the file names):
>
>package Apache::AAM;
>. . .
>package File::NCopy;
>use subs qw(glob);
>sub glob {@_};
>package Apache::AAM;
>. . .
>
>Is there a better way to do this?
Drew Taylor JA[P|m_p|SQL]H
http://www.drewtaylor.com/ Just Another Perl|mod_perl|SQL Hacker
mailto:drew@drewtaylor.com *** God bless America! ***