C<use autodie> unravels C<use strict>

------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: inline
Content-Description: a letter from tchrist
Content-ID: <10727.1298817978.1@chthon>

Everything I touch today crumbles in my hands.

When you use autodie, you implicitly declare legal
any scalar variable whose name matches that of any
function it "fatalizes".

Here's a (partial) dump of %main:: during the compilation
and run of the enclosed program:

    BEFORE AUTODIE  => $0 @ARGV %ENV @INC %INC @_ &dump_main &func1 &funcU
    AFTER AUTODIE   => $0 @ARGV %DOES %ENV @INC %INC %SIG @_ &accept &bind &binmode &carp &chdir &close &closedir &confess &connect &croak &dbmclose &dbmopen &dump_main &fcntl &fileno &flock &fork &func1 &funcU &getsockopt &ioctl &link &listen &mkdir &msgctl &msgget &msgrcv &msgsnd &open &opendir &pipe &read &readlink &recv &rename &rmdir &seek &semctl &semget &semop &send &setsockopt &shmctl &shmget &shmread &shutdown &socketpair &symlink &sysopen &sysread &sysseek &syswrite &truncate &umask &unlink
    DONE COMPILING  => $0 @ARGV %DOES %ENV @INC %INC %SIG @_ &carp &confess &croak &dump_main &func1 &funcU
    BEGIN PROGRAM   => $0 @ARGV %DOES %ENV @INC %INC %SIG @_ &carp &confess &croak &dump_main &func1 &funcU
    END PROGRAM     => $0 @ARGV %DOES %ENV @INC %INC %SIG @_ &carp &confess &croak &dump_main $fork &func1 $func1 &funcU $funcU $open $pipe $read $recv $seek $send

Blech!

Tested under v5.12.3, v5.13.9, and v5.13.10-33-g149d510.

--tom


------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="us-ascii"; name="broken-autodie"; filename="broken-autodie"
Content-Disposition: inline
Content-Description: the broken-autodie demo program
Content-ID: <10727.1298817978.2@chthon>

use strict;
use warnings;

use feature "say";

sub func1 { return 1 }
sub funcU { return undef }

sub dump_main($) {
    my $arg = shift();
    print "\U$arg\t=> ";
    for my $symbol (sort grep { /^\w+$/ } keys %main::) {
	local *GLOB = $main::{$symbol};
	print '&', $symbol, " " if *GLOB{CODE};
	print '$', $symbol, " " if *GLOB{SCALAR} && defined ${ *GLOB{SCALAR} };
	print '@', $symbol, " " if *GLOB{ARRAY};
	print '%', $symbol, " " if *GLOB{HASH};
    } 
    print "\n";
} 


END   { dump_main("end program")     } 
CHECK { dump_main("done compiling")  }  
INIT  { dump_main("begin program")   } 
BEGIN { dump_main("before autodie")  }
use autodie qw[ :default func1 funcU ];
BEGIN { dump_main("after autodie")   }

# C<use autodie> makes all these package globals legal under use strict!!

$fork = 1;
$open = 1;
$pipe = 1;
$read = 1;
$recv = 1;
$seek = 1;
$send = 1;

$func1 = 1;
$funcU = 1;

------- =_aaaaaaaaaa0--
0
tchrist
2/27/2011 2:48:55 PM
perl.perl5.porters 48287 articles. 1 followers. Follow

2 Replies
987 Views

Similar Articles

[PageSpeed] 11
Get it on Google Play
Get it on Apple App Store

Bug #2: *I* never imported Carp into main::, 
        so why am I being polluted by autodie??

--tom
0
tchrist
2/27/2011 2:51:36 PM
On 02/28/2011 01:48 AM, Tom Christiansen wrote:

> When you use autodie, you implicitly declare legal
> any scalar variable whose name matches that of any
> function it "fatalizes".

> Bug #2: *I* never imported Carp into main::,
>         so why am I being polluted by autodie??

Gah, stuck in the middle of the World's Longest Company Tax Return, but 
neither of those are intended behaviour.

The Carp pollution is fixed in autodie 2.10 which is on the CPAN.  A quick 
test reveals that the legalising of variable names seems to still be around.

My guess is that the Fatal::_install_subs() subroutine is to blame, but I'll 
need to do some testing to find out for sure.

Many thanks for the report!

	Paul

-- 
Paul Fenwick <pjf@perltraining.com.au> | http://perltraining.com.au/
Director of Training                   | Ph:  +61 3 9354 6001
Perl Training Australia                | Fax: +61 3 9354 2681
0
pjf
2/28/2011 5:35:08 AM
Reply:

Similar Artilces:

C<< >> vs C<< >> vs C<< x >>
Ugh. So we all know that there's this syntax for formatting codes (n=E9s "interio= r sequences") like C<< x >>. And that tokenizes as three tokens: "C<< ", open-C code "x", content " >>" close-code matching the C open-code And this is explicated by what I wrote in perlpodspec where I say that such a code... * starts with a capital letter (just US-ASCII [A-Z]) followed by two or more "<"'s, one or more whitespace characters, * any number of characters * one or more whit...

[PATCH] correctly handle C<< >> and C<<< >>> in diagnostics
This is just a quick hack; ideally someone would make it use an actual pod parser. --- perl/lib/diagnostics.pm.orig 2003-12-30 15:48:47.000000000 -0800 +++ perl/lib/diagnostics.pm 2004-05-25 01:54:31.735904000 -0700 @@ -314,10 +314,10 @@ sub noop { return $_[0] } # spensive for a noop sub bold { my $str =$_[0]; $str =~ s/(.)/$1\b$1/g; return $str; } sub italic { my $str = $_[0]; $str =~ s/(.)/_\b$1/g; return $str; } - s/[BC]<(.*?)>/bold($1)/ges; + s/C<<< (.*?) >>>|C<< (.*?) >>|[BC]<(.*?)>/bold($+)/ges; ...

RFC 199 (v2) Short-circuiting C<grep>, C<map>, and C<reduce> with C<last>
(or "Allowing built-in functions to use loop blocks") Reply-To: perl6-language@perl.org This and other RFCs are available on the web at http://dev.perl.org/rfc/ =head1 TITLE Short-circuiting C<grep>, C<map>, and C<reduce> with C<last> (or "Allowing built-in functions to use loop blocks") =head1 VERSION Maintainer: Garrett Goebel <garrett@scriptpro.com> Date: 6 Sep 2000 Last Modified: 7 Sep 2000 Mailing List: perl6-language@perl.org Number: 199 Version: 2 Status: Developing =head1 ABSTRACT Allow buil...

[PATCH] Fix POD: C<...->...> => C<< ...-> ... >>
--=-0nPiZliXhb80VRfJ/8qX Content-Type: text/plain Content-Transfer-Encoding: 7bit See the attached patch, it fixes some POD which gets rendered wrong by newer POD rendering tools. Thanks, Frank --=-0nPiZliXhb80VRfJ/8qX Content-Disposition: attachment; filename="0001-Fix-POD-C-.-.-C.patch" Content-Type: text/x-patch; name="0001-Fix-POD-C-.-.-C.patch"; charset="UTF-8" Content-Transfer-Encoding: 7bit From ed46d8dd56e57d51347cb0a7a6397687ee15a950 Mon Sep 17 00:00:00 2001 From: Frank Wiegand <frank.wiegand@gmail.com> Date: Thu, 19 Nov 2009 1...

r31680 -[S32/Temporal] Added to Date: "There are also C<week>, C<week-year>, C<week-number>, C<weekday-of-month>, and C<day-of-year> methods, which work just like their DateTime equivalents."
Author: Kodi Date: 2010-07-14 16:35:46 +0200 (Wed, 14 Jul 2010) New Revision: 31680 Modified: docs/Perl6/Spec/S32-setting-library/Temporal.pod Log: [S32/Temporal] Added to Date: "There are also C<week>, C<week-year>, C<week-number>, C<weekday-of-month>, and C<day-of-year> methods, which work just like their DateTime equivalents." Modified: docs/Perl6/Spec/S32-setting-library/Temporal.pod =================================================================== --- docs/Perl6/Spec/S32-setting-library/Temporal.pod 2010-07-14 14:35:21 UTC (rev 316...

Should C<grep> and C<reverse> work in C<Any> ?
Do C<grep> and C<reverse> act like the C<join> method, in that they work for C<Any> object and not just objects of type C<List>? In other words,, should C< $x.grep(...) > work even if $x isn't normally a list type? Pm --- On Sun, 29/6/08, Patrick R. Michaud <pmichaud@pobox.com> wrote: > Do C<grep> and C<reverse> act like the > C<join> method, in that > they work for C<Any> object and not just objects of > type C<List>? >=20 > In other words,, should C< $x.grep(...) > work e...

C<croak> in XS does C<die> not C<croak>
I just saw a question on comp.lang.perl.modules where the error message: Bad arg length for Socket::unpack_sockaddr_in, [...] at C:/Perl/lib/Socket.pm line 295. understandably confused a user who had simply passed an invalid argument to C<sockaddr_in>. This is exactly the situation that C<Carp::croak> is meant to avoid so it is unfortunate in this case that, in XS code, C<croak> acts like C<die> and not like C<Carp::croak>. Anyone recall past discussions on whether XS C<croak> should be able to skip up the call stack until it finds a...

RFC 151 (v1) Merge C<$!>, C<$^E>, and C<$@>
This and other RFCs are available on the web at http://dev.perl.org/rfc/ =head1 TITLE Merge C<$!>, C<$^E>, and C<$@> =head1 VERSION Maintainer: Peter Scott <Peter@PSDT.com> Date: 24 Aug 2000 Version: 1 Mailing List: perl6-language@perl.org Number: 151 =head1 ABSTRACT The distinction between the C<$!>, C<$^E>, and C<$@> variables is no longer worth trading for the benefits to be gained from merging them together. =head1 DESCRIPTION The C<$!> variable made excellent sense in Perl 4 as a repre...

RFC 300 (v1) C<use unicode::representation> and C<no unicode>
This and other RFCs are available on the web at http://dev.perl.org/rfc/ =head1 TITLE C<use unicode::representation> and C<no unicode> =head1 VERSION Maintainer: Simon Cozens <simon@brecon.co.uk> Date: 25 Sep 2000 Mailing List: perl6-internals@perl.org Number: 300 Version: 1 Status: Developing =head1 ABSTRACT Perl 5.6's C<use bytes> is a useful pragma; this RFC stipulates its intended behaviour in Perl 6 B<right now>. =head1 DESCRIPTION When Perl 5.6 introduced Unicode support, there suddenly became two ways of han...

docpatch concerning scoping operators in argument lists to C<use> and C<no>
I would ask the MCFs for a new warning to go along with this but they have too much on their plate as is. The followingly documented nuance of C<use Module LIST> has thankfully broken stricture for me repeatedly as I like to my my variables the first time I work with them instead of in advance, and I like to manipulate the @_ aliases within my import subroutines. For instance, I'll try to set up semantics allowing use specialkindofvariable my $foo; # won't DWIM! see below but instead I need to my that $foo ahead of time. At least I have succeeded in hiding...

RFC 199 (v1) Short-circuiting C<grep> and C<map> with C<last>
This and other RFCs are available on the web at http://dev.perl.org/rfc/ =head1 TITLE Short-circuiting C<grep> and C<map> with C<last> =head1 VERSION Maintainer: Garrett Goebel <garrett@scriptpro.com> Date: 6 Sep 2000 Mailing List: perl6-language@perl.org Version: 1 Number: 199 Status: Developing =head1 ABSTRACT Allow functions like C<grep> and C<map> with implicit loop blocks to be short circuited with C<last>. =head1 DESCRIPTION It'd be nice if one could use C<grep> to find out if a value is hel...

Re: RFC 199 (v1) Short-circuiting C<grep> and C<map> with C<last>
Just to note that RFC 76 (Builtin: reduce) also proposes this mechanism as a means of short-circuiting C<reduce>. Damian ...

Use of <code>, <var>, <kbd>, and <samp>
Is there any policy as to whether <code>, <var>, <kbd> and <samp> can all be used, and if so, whether they should only be used for XUL, etc. or other code documented at the site, or whether they can also be used to refer to code which is not intended as the subject of any documentation, but which is used as an example. For example, the template tutorial indicates that <content>'s @uri attribute can be set to any variable name, such as "?start" or "?uri". Could these be referenced with <var> too, or is it the policy to co...

VB <<<>>> C#
it will be usefull to have a good Vb C# | C# Vb translatorangiras I'll ask around and see if I can find out if we're planning to offer translation. In the meantime, you can find a number of them on the web, and you can also look into the DTE (our automation model) Code Model - you may be able to use it to do some interesting forms of translation. -ScottThis posting is provided "AS IS" with no warranties, and confers no rights. I have never heard about this code model ! thanksangiras they say Namespace: EnvDTE I cannot find it is it Microsofz.Win32 ?angiras The EnvDTE DL...

Web resources about - C<use autodie> unravels C<use strict> - perl.perl5.porters

Resources last updated: 1/21/2016 8:01:48 AM