Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

By the way, if that BEGIN block will end up being use statement, use subs is not needed. For example,

use strict; use warnings; package override; sub import { my ($class, $sub_name, $sub) = @_; my $pkg_name = caller(); my $pkg_sym = _pkg_symtab($pkg_name); delete $pkg_sym->{$sub_name}; if ($sub) { no strict 'refs'; *{"${pkg_name}::$sub_name"} = $sub; } } sub _pkg_symtab { my ($pkg) = @_; my $p = \%::; $p = $p->{"${_}::"} for split /::/, $pkg; return $p; } 1;

use strict; use warnings; open(my $fh, '<', $0); # Calls CORE::open use override open => sub { print "Hi\n"; }; open(my $fh2, '<', $0); # Prints Hi use override open => sub { print "Ho\n"; }; open(my $fh4, '<', $0); # Prints Ho use override open => undef; open(my $fh5, '<', $0); # Calls CORE::open


>perl Hi Ho

From there, I guess the idea is to make overrideautodie a lexical pragma. Shouldn't be too hard.

In reply to Re: Using delete package::{subroutine} to change resolution of subroutines by ikegami
in thread Using delete package::{subroutine} to change resolution of subroutines by pjf

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?

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-06-25 12:15 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.