Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Exporter. Correct way to override import?

by ikegami (Patriarch)
on May 06, 2018 at 01:12 UTC ( [id://1214104]=note: print w/replies, xml ) Need Help??


in reply to Exporter. Correct way to override import?

Exporter uses caller or similar to determine to which package to export. The caller is in package Foo in your example, which is why it's failing. You want

sub import { ... Exporter->export_to_level(1, @_); ... }
or
sub import { ... goto &Exporter::import; }

Get rid of archaic our @ISA = 'Exporter';. It doesn't make sense, and it hasn't been necessary since 5.8.3 (2004).

Replies are listed 'Best First'.
Re^2: Exporter. Correct way to override import?
by afoken (Chancellor) on May 06, 2018 at 11:04 UTC
    Get rid of archaic our @ISA = 'Exporter';. It doesn't make sense, and it hasn't been necessary since 5.8.3 (2004).

    Correct. But it is still (as of version 5.72) the documented as a valid way to use Exporter. To make things worse, it is still the first example in the Synopsis, and it is in "Good Practices". See also Re^2: Advice on style, 7.5 years ago. There are no relevant changes in the documentation in the last 10 years / 9 versions: http://search.cpan.org/diff?from=Exporter-5.63&to=Exporter-5.72&w=1#lib/Exporter.pm

    Alexander


    Update: Fixed diff link and number of versions (was diff'ing between 5.63 and 5.70)

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      So what? Even if it is presented as an option, you should still not pick the version that makes no sense (unless you need compatibility with pre-5.8.3 builds of Perl).

        I had no time to answer earlier, but I fully agree with afoken.

        Unfortunately do the perldocs often reflect only an archaic Perl.

        It's no wonder if beginners become confused and frustrated.

        For instance we keep telling them to use strict and declare variables while a big part of the docs isn't strict at all.

        I consider this a real problem, because it's damaging the reputation of Perl.

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1214104]
help
Chatterbox?
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-04-20 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found