develooper Front page | perl.perl5.porters | Postings from March 2008

RFC: "use lethal", a lexical Fatal for Perl 5.10

Thread Next
Paul Fenwick
March 9, 2008 07:33
RFC: "use lethal", a lexical Fatal for Perl 5.10
Message ID:
Hash: SHA1

G'day wonderful p5pers,

With Perl 5.10 released and the ability to write lexical pragmata easily,
I've started scratching a long-standing itch of mine, that of
having package-wide scope.

The result is current a proof-of-concept called 'lethal'[1], which exists as
a separate module that uses Fatal to do the heavy lifting.  The results look
like this:

	use lethal qw(open close);
	open(my $fh, '<', 'some_file);            # Dies on error.

		no lethal 'open';
		open(my $fh2, '<', 'other_file'); # Fails silently.
		close($fh);                       # Dies on error.

		no lethal;
		close($fh2);                      # Fails silently.


	close($fh3);                              # Dies on error.

I'm happy releasing this as a stand-alone module, but I've had more than one
suggestion that this should be integrated into Perl's core Fatal module,
perhaps with a syntax like:

	use Fatal qw(:lexical open close chdir);
	no  Fatal qw(:lexical open);
	no  Fatal qw(close);		# Lexical assumed

Modifying Fatal means that potentially everyone with Perl 5.10.1 can have
the lexical behaviour (or 5.10.0+CPAN if we dual-life Fatal), which I hope
is a fairly intuitive leap from what we have now.  It also makes my code a
little easier,

On the other hand, I see adding a :lexical option to Fatal as a potential
source of bugs.  It's easy to leave out by accident (resulting in
package-wide changes), the upper-case letter means it doesn't look like it
has lexical scope (although the :lexical says otherwise), and it's easy to
feel that it should be backwards compatible when it's not.  "use lethal"
avoids these problems.

It's at this point where I need your help; in particular your feedback and
thoughts.  Should I be aiming to modify Fatal?  Should this be released as a
stand-alone module?  Is there anything special I should be aware of when
thinking to suggest changes to any of Perl's core modules?

For reference, there's also been some discussion about this on Perlmonks
<> and

Many thanks in advance,


[1] Originally I was toying with the names 'fatal', 'lexfatal', and
'exceptions'.  Thanks to BrowserUk @ PerlMonks for the name 'lethal'.

- --
Paul Fenwick <> |
Director of Training                   | Ph:  +61 3 9354 6001
Perl Training Australia                | Fax: +61 3 9354 2681
Version: GnuPG v1.4.5 (MingW32)


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About