Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Overridding subroutines called in private subroutines

by blazar (Canon)
on Oct 21, 2008 at 10:13 UTC ( [id://718440]=note: print w/replies, xml ) Need Help??


in reply to Overridding subroutines called in private subroutines

I'm attempting to override the, "absUrl" method, which isn't really a method at all - but just a subroutine in the module itself.

(First of all, apologies for replying so late!)

So, why are you saying it's a method at all? (If it's not called like a method, then it's not a method...) Apart that in Perl 5 methods and subroutines are exactly the same thing, but for how they are called...

The only weirdness I can find in this module is that the absUrl subroutine is only called in MIME::Lite::HTML itself in private subroutines of the, "parse" method, like this:

Nope: in Perl 5 there's no notion of private subs to other methods/subs. Of course there's nothing strictly wrong declaring and defining it there, but it would be just as if it where declared outside of the body of the surrounding sub. Except for having access to some lexical variables of the latter: but remember that it won't close over them! To do so, you can use an anonymous sub and assign it to a lexical, which gets as close as possible to the concept of a "private sub" IMO.

The only way I can get it to do what I want to do is to have something like:

sub MIME::Lite::HTML::absURL($,$){

in my code - which I don't think is valid Perl code (works alright in all, though)

I'm not sure if I understand what you mean. If it compiles, then it's valid Perl. However, since nobody has pointed it out thus far, the comma is not a valid character in prototypes and if you use warnings perl will duly warn you:

C:\temp>perl -ce "sub a ($,$) {}" -e syntax OK C:\temp>perl -wce "sub a ($,$) {}" Illegal character in prototype for main::a : $,$ at -e line 1. -e syntax OK

Without warnings, I presume that the comma is silently ignored. I was trying to use B::Concise to check whether that's actually the case, but I don't really know how it works, and appearently it ignores prototypes at all, nor does it even mention it in the docs, as a quick check revealed. All I can do is to naively run the following tests:

C:\temp>perl -wMO=Concise,a -e "sub a ($,$) {}" Illegal character in prototype for main::a : $,$ at -e line 1. main::a: 2 <1> leavesub[1 ref] K/REFC,1 ->(end) 1 <;> nextstate(main 2 -e:1) P:{ ->2 -e syntax OK C:\temp>perl -wMO=Concise,a -e "sub a ($$) {}" main::a: 2 <1> leavesub[1 ref] K/REFC,1 ->(end) 1 <;> nextstate(main 2 -e:1) P:{ ->2 -e syntax OK C:\temp>perl -wMO=Concise,a -e "sub a {}" main::a: 2 <1> leavesub[1 ref] K/REFC,1 ->(end) 1 <;> nextstate(main 2 -e:1) P:{ ->2 -e syntax OK
--
If you can't understand the incipit, then please check the IPB Campaign.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-19 23:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found