<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -3,6 +3,8 @@ Revision history for Fatal
 1.09
 	* Many changes not documented here.
 	* Fatal is now fully backwaards compatible again.
+	* system() can be fatalised/autodying if IPC::System::Simple
+	  is installed.
 
 1.08	Sat Mar 29 10:54:20 AUSEDT 2008
         Dual-lifed module internally from work I was doing on p5p.</diff>
      <filename>Changes</filename>
    </modified>
    <modified>
      <diff>@@ -6,5 +6,6 @@ name(		'autodie');
 all_from(	'lib/autodie.pm');
 test_requires(	'Test::More');
 requires(	'perl' =&gt; '5.10.0');
+recommends(	'IPC::System::Simple' =&gt; '0.12'); # For autodying system()
 
 WriteAll();</diff>
      <filename>Makefile.PL</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,9 @@
 This is not an exhaustive list of TODO items.
 
+* Make sure system() returns a real exception object, not just a string.
+
+* Test cases needed for checking for old IPC::System::Simple versions.
+
 * Consider removing :lexical tests in t/* and convert them to using
   autodie.  The :lexical option is no longer officially supported in
   Fatal.
@@ -10,10 +14,6 @@ This is not an exhaustive list of TODO items.
 
 * Trawl through perlfunc to find which things autodie may apply to.
 
-* Make system() Fatalise/autodieable.
-
-    * Q: Can we use IPC::System::Simple for this?
-
 * Generate a good way to allow subroutines to register themselves
   with roles and message handlers, possibly defining their own
   exception handler to use.</diff>
      <filename>TODO</filename>
    </modified>
    <modified>
      <diff>@@ -31,10 +31,16 @@ use constant ERROR_NOTSUB    =&gt; &quot;%s is not a Perl subroutine&quot;;
 use constant ERROR_NOT_BUILT =&gt; &quot;%s is neither a builtin, nor a Perl subroutine&quot;;
 use constant ERROR_CANT_OVERRIDE =&gt; &quot;Cannot make the non-overridable builtin %s fatal&quot;;
 
+use constant ERROR_NO_IPC_SYS_SIMPLE =&gt; &quot;IPC::System::Simple required for Fatalised/autodying system()&quot;;
+
+use constant ERROR_IPC_SYS_SIMPLE_OLD =&gt; &quot;IPC::System::Simple version %f required for Fatalised/autodying system().  We only have version %f&quot;;
+
 use constant ERROR_AUTODIE_CONFLICT =&gt; q{&quot;no autodie '%s'&quot; is not allowed while &quot;use Fatal '%s'&quot; is in effect};
 
 use constant ERROR_FATAL_CONFLICT =&gt; q{&quot;use Fatal '%s'&quot; is not allowed while &quot;no autodie '%s'&quot; is in effect};
 
+use constant MIN_IPC_SYS_SIMPLE_VER =&gt; 0.12;
+
 our $VERSION = 1.08;
 our $Debug //= 0;
 
@@ -481,14 +487,38 @@ sub _make_fatal {
         croak(sprintf(ERROR_NOTSUB,$sub));
 
     } elsif ($name eq 'system') {
-        # XXX - Experimental.  Just testing for system is
-        # incomplete (what about CORE::system), and it doesn't have
-        # a prototype.
 
-        $real_proto = '';
-        $proto = '@';
-        $core = 1;
-        $call = 'CORE::system';
+        eval {
+            require IPC::System::Simple; # Only load it if we need it.
+        };
+
+        # TODO: IPC::System::Simple doesn't currently return
+        # exception objects, only strings.  We should check for
+        # a particular version number, and make sure it does the
+        # right thing with regards to exceptions.
+
+        # Alternatively, (and possibly betterly) we should use
+        # IPC::System::Simple for the heavy lifting, and mint our
+        # own error objects.
+
+        if ($@) { croak ERROR_NO_IPC_SYS_SIMPLE; }
+
+	# Make sure we're using a recent version of ISS that actually
+	# support fatalised system.
+	if ($IPC::System::Simple::VERSION &lt; MIN_IPC_SYS_SIMPLE_VER) {
+	    croak sprintf(
+                ERROR_IPC_SYS_SIMPLE_OLD, MIN_IPC_SYS_SIMPLE_VER,
+		$IPC::System::Simple::VERSION
+	    );
+	}
+
+        {
+            no strict 'refs'; # To avoid can't use string() as symbol ref.
+            no warnings;      # Avoids sub redefined warnings.
+            *{$sub} = \&amp;IPC::System::Simple::system;
+        }
+
+        return;
 
     } else {            # CORE subroutine
         $proto = eval { prototype &quot;CORE::$name&quot; };</diff>
      <filename>lib/Fatal.pm</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>2973a1816326d8802297841acb8c1a9f77efcac5</id>
    </parent>
  </parents>
  <author>
    <name>Paul Fenwick</name>
    <email>pjf@perltraining.com.au</email>
  </author>
  <url>http://github.com/pfenwick/autodie/commit/770a2a08032df0004e5a2bc7237dbc9ef392f8f1</url>
  <id>770a2a08032df0004e5a2bc7237dbc9ef392f8f1</id>
  <committed-date>2008-06-09T20:44:19-07:00</committed-date>
  <authored-date>2008-06-09T20:44:19-07:00</authored-date>
  <message>Support for Fatalised system() via IPC::System::Simple.

Currently this DOESN'T produce exception objects.  It only produces
simple string errors, since that's what IPC::System::Simple gives us.

We'll need to update autodie to wrap the string in its own exception,
or update Fatal to throw compatible objects.  I favour the earlier choice.</message>
  <tree>dd2d199cd2ed1305143b426a1431ab2af9237a4c</tree>
  <committer>
    <name>Paul Fenwick</name>
    <email>pjf@perltraining.com.au</email>
  </committer>
</commit>
