Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Cancel/no-op a require

by tobyink (Abbot)
on Dec 07, 2012 at 13:35 UTC ( #1007735=note: print w/ replies, xml ) Need Help??


in reply to Cancel/no-op a require

Also, if you really want to use a hook in @INC, this is how they work...

unshift @INC, sub { my $module = $_[1]; if ($module eq 'Foo.pm') { $INC{$module}++; my $line = 0; return sub { unless ($line++) { $_ = "1;\n"; return 1; } return 0; } } return; }; require Foo; # no-op
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re: Cancel/no-op a require
Select or Download Code
Re^2: Cancel/no-op a require
by sedusedan (Monk) on Dec 07, 2012 at 13:44 UTC

    Ah, so this particular sentence in perlfunc is the one that gets me confused: The subroutine should return either nothing or else a list of up to three values in the following order.

    So instead of returning (undef, sub{...}) I should've just returned (sub {...}).

    Thanks, Toby.

      Also the innards of the function are kinda odd. You need to assign lines to $_ rather than returning them. I can understand why they did it that way, but it's pretty strange.

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1007735]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (13)
As of 2014-04-23 11:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (541 votes), past polls