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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.

In reply to Re: Overridding subroutines called in private subroutines by blazar
in thread Overridding subroutines called in private subroutines by skazat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found