I know you requested no lectures, but the code you posted had some fundamental errors that make me wonder whether it is a good idea for you to be playing with fire. It's your business if you want to hang yourself, but I feel uneasy handing you the rope for it. I just had to get this off my chest. OK, end of sermonette.

I found at least three major errors in your code (more if all the code was intended to reside in a single file). The first one is that it's package, all lower case. What you wrote is equivalent to Foo->Package (see perlobj) . Next, it is not enough to use Exporter; you need to make your class a subclass of it. Like this:

package Foo; use Exporter; our @ISA = ( 'Exporter' );
or (my preferred idiom):
package Foo; use base 'Exporter';
(There are more idioms for doing this; see perlobj). The third thing is that the entries in @EXPORT, @EXPORT_OK, etc. are supposed to be strings. Something like @EXPORT_OK = ( &frobozz ) will put the value returned by the frobozz subroutine (whatever that is) in @EXPORT_OK, which, unless frobozz is the rare function that narcissistically returns its own name, won't do you any good.

OK, so here's what you do:

# file Foo.pm package Foo; use strict; use warnings; use Exporter; our @ISA = ( 'Exporter' ); our @EXPORT_OK = ( 'sysread' ); sub sysread { warn "this is not the real thing\n"; } 1; __END__ # file test.pl use strict; use warnings; package Bar; use Foo 'sysread'; warn "about to test sysread\n"; sysread; __END__ % perl test.pl about to test sysread this is not the real thing
Note that the code in the example above is split over two files; it won't work as written if you put it all in one file.

Definitely give a very good read or two to the relevant section of perlsub that I cited before.

the lowliest monk


In reply to Re^3: using Exporter to overwrite a core function by tlm
in thread using Exporter to overwrite a core function by Forsaken

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.