Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Getting rid of "new"

by ruoso (Curate)
on Jul 10, 2006 at 17:35 UTC ( #560186=note: print w/replies, xml ) Need Help??


in reply to Getting rid of "new"

If we're talking about nuts, well... here's a weird faulty working version... :)

package a::b; use strict; sub a::b { my @l = caller(0); open my $f, "<", $l[1]; my $line; for (0..$l[2] - 1) { $line = <$f>; } my $pack = $l[3]; if (!@_ && $line =~ /$pack\->/) { return $pack; } else { return $pack->new(@_); } } sub new { print "new!!! ".join(", ",@_)."\n"; } sub c { print "a::b->c()!!!! ".join(", ",@_)."\n"; } package main; a::b; a::b('a'); a::b->c; a::b->c('a');

UPDATE: use of __DATA__ substituted by opening the file itself...

daniel

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2020-12-05 11:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (63 votes). Check out past polls.

    Notices?