Perl, warning does not work after XML :: Smart save

I realized that there is a warning issue after using XML :: Smart save.

#!/usr/bin/perl

use strict;
use warnings;

use XML::Smart;

my $XML = XML::Smart->new() ;

print STDOUT "Before save: Print to STDOUT works\n";
print STDERR "Before save: Print to STDERR works\n";
warn "Before save: Warn works\n";

$XML->save('newfile.xml') ;

print STDOUT "After save: Print to STDOUT works\n";
print STDERR "After save: Print to STDERR works\n";
warn "After save: Warn does not work\n";

The test runs in OSX 10.8.2 perl version 5.12.4 xml-smart version 1.77

This is probably closely related to the inner workings of XML :: Smart, but is there a way to restore the warning print (reset STDERR).

[EDIT 3/19/2013]: The HP-UX Designer is also problematic. The workaround provided by ikegami below can be used for both new and rescue solutions to the problem.

+5
source share
1 answer

As TLP pointed out, the problem is with XML :: Smart fiddling c $SIG{__WARN__}.

The following is a workaround for the error:

{
    local $SIG{__WARN__} = $SIG{__WARN__};
    local $SIG{__DIE__}  = $SIG{__DIE__};
    $XML->save('newfile.xml') ;
}

, % SIG, XML:: Smart , . $XML->save.

+11

All Articles