Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: Help to override Spreadsheet/ParseXLSX.pm module (monkey-patching)

by LanX (Saint)
on Apr 03, 2021 at 12:42 UTC ( [id://11130772]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Help to override Spreadsheet/ParseXLSX.pm module
in thread Help to override Spreadsheet/ParseXLSX.pm module

It's not clear to me how you did the "sub-classing", by inheriting methods or by importing or a do or ...?

Anyway, as I already said, I prefer monkey-patching over subclassing and you won't need to create another module/namespace for it.

Sub-classing requires that the author played by "the" book, and the OOP book is indeed a TIMTOWTDI library in Perl.

Monkey-patching OTOH is well defined and has no dependency to any OOP model.

So in our own interest consider

sub call_patched { local *Spreadsheet::ParseXLSX::new = \&patched_new; local *Spreadsheet::ParseXLSX::_parse_workbook = \&patched_parse_w +orkbook; # do whatever with Spreadsheet::ParseXLSX }

And all patches will disappear outside this function.

For completeness: Both ways may fail if there are any lexical variables closed over the patched subs, but even this can be solved with PadWalker, iff this really happens.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

  • Comment on Re^3: Help to override Spreadsheet/ParseXLSX.pm module (monkey-patching)
  • Download Code

Replies are listed 'Best First'.
Re^4: Help to override Spreadsheet/ParseXLSX.pm module (monkey-patching)
by boleary (Scribe) on Apr 06, 2021 at 11:36 UTC

    Thanks Rolf! This is helpful and I will try it out...

Log In?
Username:
Password:

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

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

    No recent polls found