adrianh has asked for the wisdom of the Perl Monks concerning the following question:
I've a ghastly feeling that this is something blatantly obvious. Unfortunately I've got nobody here to tell me what exactly and the rubber duck has been surprisingly unhelpful.
Can anybody tell me why with this code:
#! /usr/bin/perl use strict; use warnings; { package SomePackage; use Exporter 'import'; our @EXPORT = ( 'hello' ); sub hello (&) { print "hello\n" } # works with the prototype inside the package hello { die "should not be called" } } SomePackage->import( 'hello' ); # works outside the package with a fully qualified name SomePackage::hello { die "should not be called" }; # works outside the package if we ignore prototypes hello( sub { die "should not be called" } ); # perl does know what the prototype is print "prototype is ", prototype \&hello, "\n"; # and yet... hello { die "should not be called" };
that last call to hello() is parsed as:
do { die 'should not be called' }->hello;
rather than as a call to SomePackage::hello
I'm off to the library and to get some coffee. Hopefully somebody will demonstrate where I'm being dim by the time I get back :-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Odd behaviour with prototypes and Exporter
by BUU (Prior) on Aug 01, 2005 at 14:24 UTC | |
by adrianh (Chancellor) on Aug 01, 2005 at 15:32 UTC |