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

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

Thread Next
From:
Paul Fenwick
Date:
March 9, 2008 07:33
Subject:
RFC: "use lethal", a lexical Fatal for Perl 5.10
Message ID:
47D3F533.1070609@perltraining.com.au
-----BEGIN PGP SIGNED MESSAGE-----
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 Fatal.pm
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
<http://perlmonks.org/?node_id=673060> and modules@perl.org
<http://www.xray.mpe.mpg.de/mailing-lists/modules/2008-03/msg00138.html>.

Many thanks in advance,

	Paul

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

- --
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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)

iD8DBQFH0/Uyx5N6j7FHnlURAtRHAJ9ZK2/a+t2TrTFA6jkoHjyM9WophgCfRuN9
XiM0KLKiHHoA+ddOLCIwVvA=
=qYv9
-----END PGP SIGNATURE-----

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About