From 81a7fe9606f6ab04fd3d366aa37fcd4aa83b4936 Mon Sep 17 00:00:00 2001 From: DongHun Kwak Date: Mon, 25 Jul 2022 10:33:30 +0900 Subject: [PATCH] Imported Upstream version 2.21 --- Changes | 15 ++++++++++ LICENSE | 22 ++++++++------- MANIFEST | 1 + META.json | 17 +++++++---- META.yml | 8 +++--- Makefile.PL | 64 ++++++++++++++++++++++-------------------- README | 6 ++-- dist.ini | 2 +- lib/XML/Simple.pm | 58 +++++++++++++++++++++----------------- lib/XML/Simple/FAQ.pod | 5 ++-- t/1_XMLin.t | 54 ++++++++++++++--------------------- t/2_XMLout.t | 37 ++++++++++++------------ t/3_Storable.t | 4 +-- t/4_MemShare.t | 3 +- t/5_MemCopy.t | 2 +- t/7_SaxStuff.t | 2 +- t/8_Namespaces.t | 6 ++-- t/A_XMLParser.t | 18 +++--------- t/B_Hooks.t | 1 - t/release-pod-syntax.t | 5 ++-- 20 files changed, 173 insertions(+), 157 deletions(-) diff --git a/Changes b/Changes index 82f4ffe..bdb8db5 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,20 @@ Revision history for XML-Simple +2.21 2015-12-04 16:33:49+13:00 Pacific/Auckland + - Improved diagnostics - xml_in() will now catch parse exceptions and add + caller information via Carp::croak + - Switch to use lexical warnings (suppress with either 'no warnings;' or + 'no warnings "XML::Simple";', rather than $^W = 0) + - POD fixes (from David Steinbrunner) + - Regex escaping fixes for Perl 5.22+ (from Kent Fredric) + - Add workaround for test failures on RHEL/CentOS 6.5 (RT#102115 from + Chris Drake, workaround from Tim Bunce) + - Remove some 'eval' calls from test suite which could mask root cause of + test failures + - Make each test script use unique filenames to allow tests to be run in + parallel (RT#101362 from Karen Etheridge & Kent Fredric) + - POD update: mention XML::Twig in 'STATUS' section (RT#79228 from Matt Trout) + 2.20 2012-06-20 22:00:13 Pacific/Auckland - Suppress warning from empty CDATA section (RT#58359 from Juan Antonio Navarro Pérez) diff --git a/LICENSE b/LICENSE index 612805d..afb727a 100644 --- a/LICENSE +++ b/LICENSE @@ -18,15 +18,16 @@ This is free software, licensed under: The GNU General Public License, Version 1, February 1989 - GNU GENERAL PUBLIC LICENSE - Version 1, February 1989 + GNU GENERAL PUBLIC LICENSE + Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA + 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA + Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. - Preamble + Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public @@ -67,7 +68,7 @@ authors' reputations. The precise terms and conditions for copying, distribution and modification follow. - GNU GENERAL PUBLIC LICENSE + GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which @@ -185,7 +186,7 @@ make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. - NO WARRANTY + NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN @@ -207,9 +208,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - END OF TERMS AND CONDITIONS + END OF TERMS AND CONDITIONS - Appendix: How to Apply These Terms to Your New Programs + Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it @@ -235,8 +236,9 @@ the exclusion of warranty; and each file should have at least the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA + Also add information on how to contact you by electronic and paper mail. diff --git a/MANIFEST b/MANIFEST index 2578206..1f34c03 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1,3 +1,4 @@ +# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.022. Changes LICENSE MANIFEST diff --git a/META.json b/META.json index 41f6e92..0c54731 100644 --- a/META.json +++ b/META.json @@ -1,10 +1,10 @@ { - "abstract" : "Easily read/write XML (esp config files)", + "abstract" : "An API for simple XML files", "author" : [ "Grant McLean " ], "dynamic_config" : 0, - "generated_by" : "Dist::Zilla version 4.200004, CPAN::Meta::Converter version 2.101670", + "generated_by" : "Dist::Zilla version 5.022, CPAN::Meta::Converter version 2.142690", "license" : [ "perl_5" ], @@ -16,14 +16,19 @@ "prereqs" : { "configure" : { "requires" : { - "ExtUtils::MakeMaker" : "6.31" + "ExtUtils::MakeMaker" : "0" + } + }, + "develop" : { + "requires" : { + "Test::Pod" : "1.41" } }, "runtime" : { "requires" : { "XML::NamespaceSupport" : "1.04", "XML::SAX" : "0.15", - "XML::SAX::Expat" : 0, + "XML::SAX::Expat" : "0", "perl" : "5.008" } }, @@ -38,9 +43,9 @@ "repository" : { "type" : "git", "url" : "git://github.com/grantm/xml-simple.git", - "web" : "http://github.com/grantm/xml-simple" + "web" : "https://github.com/grantm/xml-simple" } }, - "version" : "2.20" + "version" : "2.21" } diff --git a/META.yml b/META.yml index 79c77b1..9092f20 100644 --- a/META.yml +++ b/META.yml @@ -1,13 +1,13 @@ --- -abstract: 'Easily read/write XML (esp config files)' +abstract: 'An API for simple XML files' author: - 'Grant McLean ' build_requires: Test::More: 0.88 configure_requires: - ExtUtils::MakeMaker: 6.31 + ExtUtils::MakeMaker: 0 dynamic_config: 0 -generated_by: 'Dist::Zilla version 4.200004, CPAN::Meta::Converter version 2.101670' +generated_by: 'Dist::Zilla version 5.022, CPAN::Meta::Converter version 2.142690' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html @@ -20,4 +20,4 @@ requires: perl: 5.008 resources: repository: git://github.com/grantm/xml-simple.git -version: 2.20 +version: 2.21 diff --git a/Makefile.PL b/Makefile.PL index 94e41a5..4b40df7 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,49 +1,53 @@ +# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.022. use strict; use warnings; -BEGIN { require 5.008; } +use 5.008; -use ExtUtils::MakeMaker 6.31; +use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( - 'ABSTRACT' => 'Easily read/write XML (esp config files)', - 'AUTHOR' => 'Grant McLean ', - 'BUILD_REQUIRES' => { - 'Test::More' => '0.88' + "ABSTRACT" => "An API for simple XML files", + "AUTHOR" => "Grant McLean ", + "CONFIGURE_REQUIRES" => { + "ExtUtils::MakeMaker" => 0 }, - 'CONFIGURE_REQUIRES' => { - 'ExtUtils::MakeMaker' => '6.31' + "DISTNAME" => "XML-Simple", + "EXE_FILES" => [], + "LICENSE" => "perl", + "MIN_PERL_VERSION" => "5.008", + "NAME" => "XML::Simple", + "PREREQ_PM" => { + "XML::NamespaceSupport" => "1.04", + "XML::SAX" => "0.15", + "XML::SAX::Expat" => 0 }, - 'DISTNAME' => 'XML-Simple', - 'EXE_FILES' => [], - 'LICENSE' => 'perl', - 'NAME' => 'XML::Simple', - 'PREREQ_PM' => { - 'XML::NamespaceSupport' => '1.04', - 'XML::SAX' => '0.15', - 'XML::SAX::Expat' => '0' + "TEST_REQUIRES" => { + "Test::More" => "0.88" }, - 'VERSION' => '2.20', - 'test' => { - 'TESTS' => 't/*.t' + "VERSION" => "2.21", + "test" => { + "TESTS" => "t/*.t" } ); -unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) { - my $br = delete $WriteMakefileArgs{BUILD_REQUIRES}; - my $pp = $WriteMakefileArgs{PREREQ_PM}; - for my $mod ( keys %$br ) { - if ( exists $pp->{$mod} ) { - $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod}; - } - else { - $pp->{$mod} = $br->{$mod}; - } - } +my %FallbackPrereqs = ( + "ExtUtils::MakeMaker" => 0, + "Test::More" => "0.88", + "XML::NamespaceSupport" => "1.04", + "XML::SAX" => "0.15", + "XML::SAX::Expat" => 0 +); + + +unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { + delete $WriteMakefileArgs{TEST_REQUIRES}; + delete $WriteMakefileArgs{BUILD_REQUIRES}; + $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} diff --git a/README b/README index 2a0a8e8..07d2eb8 100644 --- a/README +++ b/README @@ -1,9 +1,9 @@ This archive contains the distribution XML-Simple, -version 2.20: +version 2.21: - Easily read/write XML (esp config files) + An API for simple XML files This software is copyright (c) 2012 by Grant McLean. @@ -11,3 +11,5 @@ This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. +This README file was generated by Dist::Zilla::Plugin::Readme v5.022. + diff --git a/dist.ini b/dist.ini index 7d474bc..771bc6b 100644 --- a/dist.ini +++ b/dist.ini @@ -1,6 +1,6 @@ name = XML-Simple author = Grant McLean -version = 2.20 +version = 2.21 license = Perl_5 copyright_holder = Grant McLean copyright_year = 2012 diff --git a/lib/XML/Simple.pm b/lib/XML/Simple.pm index 0686c10..e585f77 100644 --- a/lib/XML/Simple.pm +++ b/lib/XML/Simple.pm @@ -1,14 +1,14 @@ package XML::Simple; -BEGIN { - $XML::Simple::VERSION = '2.20'; -} - +$XML::Simple::VERSION = '2.21'; =head1 NAME -XML::Simple - Easily read/write XML (esp config files) +XML::Simple - An API for simple XML files =head1 SYNOPSIS +You really don't want to use this module in new code. If you ignore this +warning and use it anyway, the C mode will save you a little pain. + use XML::Simple qw(:strict); my $ref = XMLin([] [, ]); @@ -38,6 +38,8 @@ not to imply items should be supplied in arrayrefs. # Load essentials here, other modules loaded on demand later use strict; +use warnings; +use warnings::register; use Carp; require Exporter; @@ -326,7 +328,10 @@ sub default_config_file { sub build_simple_tree { my $self = shift; - my $tree = $self->build_tree(@_); + my $tree = eval { + $self->build_tree(@_); + }; + Carp::croak("$@XML::Simple called") if $@; return $self->{opt}->{keeproot} ? $self->collapse({}, @$tree) @@ -787,7 +792,7 @@ sub handle_options { } if(exists($opt->{parseropts})) { - if($^W) { + if(warnings::enabled()) { carp "Warning: " . "'ParserOpts' is deprecated, contact the author if you need it"; } @@ -1010,7 +1015,7 @@ sub collapse { if(my $var = $self->{_var_values}) { while(my($key, $val) = each(%$attr)) { - $val =~ s{\$\{([\w.]+)\}}{ $self->get_var($1) }ge; + $val =~ s^\$\{([\w.]+)\}^ $self->get_var($1) ^ge; $attr->{$key} = $val; } } @@ -1047,7 +1052,7 @@ sub collapse { # do variable substitutions if(my $var = $self->{_var_values}) { - $val =~ s{\$\{(\w+)\}}{ $self->get_var($1) }ge; + $val =~ s^\$\{(\w+)\}^ $self->get_var($1) ^ge; } @@ -1321,15 +1326,15 @@ sub array_to_hash { # 3. ignores message and returns silently if neither strict mode nor warnings # are enabled # -# Option 2 looks at the global warnings variable $^W - which is not really -# appropriate in the modern world of lexical warnings - TODO: Fix sub die_or_warn { my $self = shift; my $msg = shift; croak $msg if($self->{opt}->{strictmode}); - carp "Warning: $msg" if($^W); + if(warnings::enabled()) { + carp "Warning: $msg"; + } } @@ -1354,7 +1359,7 @@ sub new_hashref { # # Arguments expected are: # - an XML::Simple object -# - a hasref +# - a hashref # the hashref is a former array, turned into a hash by array_to_hash because # of the presence of key attributes # at this point collapse_content avoids over-complicated structures like @@ -1547,7 +1552,7 @@ sub value_to_xml { unless(exists($self->{opt}->{suppressempty}) and !defined($self->{opt}->{suppressempty}) ) { - carp 'Use of uninitialized value' if($^W); + carp 'Use of uninitialized value' if warnings::enabled(); } if($key eq $self->{opt}->{contentkey}) { $text_content = ''; @@ -1890,10 +1895,12 @@ __END__ The use of this module in new code is discouraged. Other modules are available which provide more straightforward and consistent interfaces. In particular, -L is highly recommended. +L is highly recommended and L is an excellent +alternative. -The major problems with this module are the large number of options and the -arbitrary ways in which these options interact - often with unexpected results. +The major problems with this module are the large number of options (some of +which have unfortunate defaults) and the arbitrary ways in which these options +interact - often producing unexpected results. Patches with bug fixes and documentation fixes are welcome, but new features are unlikely to be added. @@ -1995,7 +2002,7 @@ case, you might want to read L<"WHERE TO FROM HERE?">. The XML::Simple module provides a simple API layer on top of an underlying XML parsing module (either XML::Parser or one of the SAX2 parser modules). Two -functions are exported: C and C. Note: you can explicity +functions are exported: C and C. Note: you can explicitly request the lower case versions of the function names: C and C. @@ -2470,7 +2477,7 @@ rolled up into a scalar rather than an array and therefore will not be folded =head2 KeyAttr => { list } I<# in+out - important> -This alternative (and preferred) method of specifiying the key attributes +This alternative (and preferred) method of specifying the key attributes allows more fine grained control over which elements are folded and on which attributes. For example the option 'KeyAttr => { package => 'id' } will cause any package elements to be folded on the 'id' attribute. No other elements @@ -2479,7 +2486,8 @@ which have an 'id' attribute will be folded at all. Note: C will generate a warning (or a fatal error in L<"STRICT MODE">) if this syntax is used and an element which does not have the specified key attribute is encountered (eg: a 'package' element without an 'id' attribute, to -use the example above). Warnings will only be generated if B<-w> is in force. +use the example above). Warnings can be suppressed with the lexical +C pragma or C. Two further variations are made possible by prefixing a '+' or a '-' character to the attribute name: @@ -2944,8 +2952,8 @@ KeyAttr hash. Data error - KeyAttr is set to say { part => 'partnum' } but the XML contains one or more EpartE elements without a 'partnum' attribute (or nested -element). Note: if strict mode is not set but -w is, this condition triggers a -warning. +element). Note: if strict mode is not set but C is in force, +this condition triggers a warning. =item * @@ -3233,7 +3241,7 @@ The tag can be used to form anonymous arrays: ] } -Anonymous arrays can be nested to arbirtrary levels and as a special case, if +Anonymous arrays can be nested to arbitrary levels and as a special case, if the surrounding tags for an XML document contain only an anonymous array the arrayref will be returned directly rather than the usual hashref: @@ -3299,7 +3307,7 @@ You don't need help converting between different encodings =back In a serious XML project, you'll probably outgrow these assumptions fairly -quickly. This section of the document used to offer some advice on chosing a +quickly. This section of the document used to offer some advice on choosing a more powerful option. That advice has now grown into the 'Perl-XML FAQ' document which you can find at: L @@ -3307,7 +3315,7 @@ The advice in the FAQ boils down to a quick explanation of tree versus event based parsers and then recommends: For event based parsing, use SAX (do not set out to write any new code for -XML::Parser's handler API - it is obselete). +XML::Parser's handler API - it is obsolete). For tree-based parsing, you could choose between the 'Perlish' approach of L and more standards based DOM implementations - preferably one with diff --git a/lib/XML/Simple/FAQ.pod b/lib/XML/Simple/FAQ.pod index 4c5c904..2039b35 100644 --- a/lib/XML/Simple/FAQ.pod +++ b/lib/XML/Simple/FAQ.pod @@ -1,4 +1,5 @@ package XML::Simple::FAQ; +$XML::Simple::FAQ::VERSION = '2.21'; 1; __END__ @@ -170,7 +171,7 @@ directory under your Perl installation (typically C:\Perl). Is the directory where you've unpacked XML::Simple mounted from a file server using NFS, SMB or some other network file sharing? If so, that may cause -errors in the the following test scripts: +errors in the following test scripts: 3_Storable.t 4_MemShare.t @@ -200,7 +201,7 @@ used. Is one of the three test scripts (above) failing but you're not running on a network filesystem? Are you running Win32? If so, you may be seeing a bug -in Win32 where writes to a file do not affect its modfication timestamp. +in Win32 where writes to a file do not affect its modification timestamp. If none of these scenarios match your situation, please confirm you're running the latest version of XML::Simple and then email the output of diff --git a/t/1_XMLin.t b/t/1_XMLin.t index eb38280..84935cd 100644 --- a/t/1_XMLin.t +++ b/t/1_XMLin.t @@ -5,10 +5,7 @@ use Test::More; use IO::File; use File::Spec; - -# The suppress-able warnings still check the global flag - -$^W = 1; +use XML::Simple; # Initialise filenames and check they're there @@ -18,13 +15,11 @@ unless(-e $XMLFile) { plan skip_all => 'Test data missing'; } -plan tests => 131; +plan tests => 132; my $last_warning = ''; -$@ = ''; -eval "use XML::Simple;"; is($@, '', 'Module compiled OK'); my $version = 'unknown'; if(open my $chg, ' { item => 'name' }, @cont_key); - is_deeply($opt, $target, "did not fold on specific key with non-scalar value"); - is($last_warning, '', 'no warning issued (as expected)'); + { + no warnings 'XML::Simple'; + $opt = XMLin($xml, keyattr => { item => 'name' }, @cont_key); + is_deeply($opt, $target, "did not fold on specific key with non-scalar value"); + is($last_warning, '', 'no warning issued (as expected)'); + } $last_warning = ''; - $^W = 1; my $xitems = q( red heavy @@ -416,13 +412,14 @@ $target = { 'expected warning issued'); $last_warning = ''; - $^W = 0; - $opt = XMLin($xitems, keyattr => { item => 'name' }, @cont_key); - is_deeply($opt, $items, "same again"); - is($last_warning, '', 'but with no warning this time'); + { + no warnings; + $opt = XMLin($xitems, keyattr => { item => 'name' }, @cont_key); + is_deeply($opt, $items, "same again"); + is($last_warning, '', 'but with no warning this time'); + } $last_warning = ''; - $^W = 1; $xitems = q( red heavy @@ -448,10 +445,12 @@ $target = { 'expected warning issued'); $last_warning = ''; - $^W = 0; - $opt = XMLin($xitems, keyattr => { item => 'name' }, @cont_key); - is_deeply($opt, $items, "same again"); - is($last_warning, '', 'but with no warning this time'); + { + no warnings; + $opt = XMLin($xitems, keyattr => { item => 'name' }, @cont_key); + is_deeply($opt, $items, "same again"); + is($last_warning, '', 'but with no warning this time'); + } } @@ -485,7 +484,6 @@ is_deeply($opt, { # Try parsing a named external file -$@ = ''; $opt = eval{ XMLin($XMLFile); }; is($@, '', "XMLin didn't choke on named external file"); is_deeply($opt, { @@ -495,7 +493,6 @@ is_deeply($opt, { # Try parsing default external file (scriptname.xml in script directory) -$@ = ''; $opt = eval { XMLin(); }; is($@, '', "XMLin didn't choke on un-named (default) external file"); is_deeply($opt, { @@ -505,7 +502,6 @@ is_deeply($opt, { # Try parsing named file in a directory in the searchpath -$@ = ''; $opt = eval { XMLin('test2.xml', searchpath => [ 'dir1', 'dir2', File::Spec->catdir('t', 'subdir'), @cont_key @@ -520,7 +516,6 @@ is_deeply($opt, { # Ensure we get expected result if file does not exist -$@ = ''; $opt = undef; $opt = eval { XMLin('bogusfile.xml', searchpath => 't' ); # should 'die' @@ -531,7 +526,6 @@ like($@, qr/Could not find bogusfile.xml in/, 'with the expected message'); # same again, but with no searchpath -$@ = ''; $opt = undef; $opt = eval { XMLin('bogusfile.xml'); }; is($opt, undef, 'nonexistant file not found in current directory'); @@ -540,17 +534,16 @@ like($@, qr/File does not exist: bogusfile.xml/, 'with the expected message'); # Confirm searchpath is ignored if filename includes directory component -$@ = ''; $opt = undef; $opt = eval { XMLin(File::Spec->catfile('subdir', 'test2.xml'), searchpath => 't' ); }; is($opt, undef, 'search path ignored when pathname supplied'); +like($@, qr/Could not find/, 'failed with expected message'); # Try parsing from an IO::Handle -$@ = ''; my $fh = new IO::File; $XMLFile = File::Spec->catfile('t', '1_XMLin.xml'); # t/1_XMLin.xml eval { @@ -564,7 +557,6 @@ is($opt->{location}, 't/1_XMLin.xml', 'and it parsed the right file'); # Try parsing from STDIN close(STDIN); -$@ = ''; eval { open(STDIN, $XMLFile) || die "$!"; $opt = XMLin('-'); @@ -1219,13 +1211,11 @@ is_deeply($opt, { # Confirm only a hash is acceptable to grouptags and variables -$@ = ''; $_ = eval { $opt = XMLin($xml, grouptags => [ 'dir' ]); }; ok(!defined($_), 'grouptags requires a hash'); like($@, qr/Illegal value for 'GroupTags' option - expected a hashref/, 'with correct error message'); -$@ = ''; $_ = eval { $opt = XMLin($xml, variables => [ 'dir' ]); }; ok(!defined($_), 'variables requires a hash'); like($@, qr/Illegal value for 'Variables' option - expected a hashref/, @@ -1253,12 +1243,10 @@ is_deeply($opt, { # Test option error handling -$@=''; $_ = eval { XMLin('', rootname => 'fred') }; # not valid for XMLin() is($_, undef, 'invalid options are trapped'); like($@, qr/Unrecognised option:/, 'with correct error message'); -$@=''; $_ = eval { XMLin('', 'searchpath') }; is($_, undef, 'invalid number of options are trapped'); like($@, qr/Options must be name=>value pairs \(odd number supplied\)/, diff --git a/t/2_XMLout.t b/t/2_XMLout.t index 5069c8d..edee6f7 100644 --- a/t/2_XMLout.t +++ b/t/2_XMLout.t @@ -3,6 +3,8 @@ use strict; use warnings; use Test::More; +use FileHandle; # Workaround for test failures on RHEL + plan tests => 201; @@ -517,7 +519,7 @@ unlink($TestFile); ok(!-e $TestFile, 'output file does not exist'); $xml = XMLout($hashref1); -eval { XMLout($hashref1, outputfile => $TestFile); }; +XMLout($hashref1, outputfile => $TestFile); ok(-e $TestFile, 'created xml output file'); is(ReadFile($TestFile), $xml, 'Contents match expectations'); unlink($TestFile); @@ -526,11 +528,9 @@ unlink($TestFile); # Test output to an IO handle ok(!-e $TestFile); -eval { - open my $fh, '>', $TestFile or die "$!"; - XMLout($hashref1, outputfile => $fh); - $fh->close(); -}; +open my $fh, '>', $TestFile or die "$!"; +XMLout($hashref1, outputfile => $fh); +$fh->close(); ok(-e $TestFile, 'create XML output file via IO::File'); is(ReadFile($TestFile), $xml, 'Contents match expectations'); unlink($TestFile); @@ -646,7 +646,6 @@ like($_, qr{^\s*<(\w+)\s*>\s*\s*\s*\s*$}, 'document OK'); # Check undefined values generate warnings { - local($^W) = 1; my $warn = ''; local $SIG{__WARN__} = sub { $warn = $_[0] }; $ref = { 'one' => 1, 'two' => undef }; @@ -656,10 +655,15 @@ like($_, qr{^\s*<(\w+)\s*>\s*\s*\s*\s*$}, 'document OK'); like($warn, qr/Use of uninitialized value/, 'caught warning re uninitialised value'); like($_, $expect, 'undef maps to any empty attribute by default'); +} +{ # unless warnings are disabled - $^W = 0; - $warn = ''; + no warnings; + my $warn = ''; + local $SIG{__WARN__} = sub { $warn = $_[0] }; + my $expect = qr/^<\w+(\s+one="1"|\s+two=""){2}/; + $_ = XMLout($ref); is($warn, '', 'no warning re uninitialised value if warnings off'); like($_, $expect, 'undef still maps to any empty attribute'); @@ -754,18 +758,15 @@ like($_, qr{^\s*text\s*$}s, 'even with "-" prefix'); # Confirm content key works with undef values (and no warnings) { - $^W = 1; my $warn = ''; local $SIG{__WARN__} = sub { $warn = $_[0] }; - $_ = eval { - $ref = { - column => [ - { name => 'title', content => 'A Title' }, - { name => 'sponsor', content => undef }, - ], - }; - XMLout($ref, suppress_empty => undef, content_key => 'content'); + $ref = { + column => [ + { name => 'title', content => 'A Title' }, + { name => 'sponsor', content => undef }, + ], }; + $_ = XMLout($ref, suppress_empty => undef, content_key => 'content'); ok(!$warn, 'no warnings with suppress_empty => undef'); like($_, qr{^<(\w+)> \s*A\sTitle diff --git a/t/3_Storable.t b/t/3_Storable.t index a98c6b4..d688226 100644 --- a/t/3_Storable.t +++ b/t/3_Storable.t @@ -17,8 +17,8 @@ unless(UNIVERSAL::can(Storable => 'lock_nstore')) { # Initialise filenames and check they're there my $SrcFile = File::Spec->catfile('t', 'desertnet.src'); -my $XMLFile = File::Spec->catfile('t', 'desertnet.xml'); -my $CacheFile = File::Spec->catfile('t', 'desertnet.stor'); +my $XMLFile = File::Spec->catfile('t', 'desertnet3.xml'); +my $CacheFile = File::Spec->catfile('t', 'desertnet3.stor'); unless(-e $SrcFile) { plan skip_all => 'test data missing'; diff --git a/t/4_MemShare.t b/t/4_MemShare.t index 2259eec..4360ed7 100644 --- a/t/4_MemShare.t +++ b/t/4_MemShare.t @@ -8,7 +8,7 @@ use File::Spec; # Initialise filenames and check they're there my $SrcFile = File::Spec->catfile('t', 'desertnet.src'); -my $XMLFile = File::Spec->catfile('t', 'desertnet.xml'); +my $XMLFile = File::Spec->catfile('t', 'desertnet4.xml'); unless(-e $SrcFile) { plan skip_all => 'test data missing'; @@ -146,6 +146,7 @@ my $opt2 = XMLin($XMLFile, cache => 'memshare'); is($opt2->{three}, 3, 'cache was modified'); +unlink($XMLFile); exit(0); diff --git a/t/5_MemCopy.t b/t/5_MemCopy.t index 4601a85..3720468 100644 --- a/t/5_MemCopy.t +++ b/t/5_MemCopy.t @@ -13,7 +13,7 @@ unless($INC{'Storable.pm'}) { # Initialise filenames and check they're there my $SrcFile = File::Spec->catfile('t', 'desertnet.src'); -my $XMLFile = File::Spec->catfile('t', 'desertnet.xml'); +my $XMLFile = File::Spec->catfile('t', 'desertnet5.xml'); unless(-e $SrcFile) { plan skip_all => 'test data missing'; diff --git a/t/7_SaxStuff.t b/t/7_SaxStuff.t index 8f70832..bc05af9 100644 --- a/t/7_SaxStuff.t +++ b/t/7_SaxStuff.t @@ -20,7 +20,7 @@ use TagsToUpper; # Initialise filenames and check they're there my $SrcFile = File::Spec->catfile('t', 'desertnet.src'); -my $XMLFile = File::Spec->catfile('t', 'desertnet.xml'); +my $XMLFile = File::Spec->catfile('t', 'desertnet7.xml'); my $CacheFile = File::Spec->catfile('t', 'desertnet.stor'); unless(-e $SrcFile) { diff --git a/t/8_Namespaces.t b/t/8_Namespaces.t index 9c83f3d..7775c5d 100644 --- a/t/8_Namespaces.t +++ b/t/8_Namespaces.t @@ -122,16 +122,16 @@ $opt = { }; $xml = XMLout($opt); -like($xml, qr{ +like($xml, qr[ ^\s* - \s*<{http://www.perl.com/}element\s*>data + \s*<\{http://www.perl.com/\}element\s*>data \s* \s*$ -}sx, 'clarkian names not converted to qnames on output by default'); +]sx, 'clarkian names not converted to qnames on output by default'); # Confirm nsexpand option works on output diff --git a/t/A_XMLParser.t b/t/A_XMLParser.t index faa4ce3..86905dd 100644 --- a/t/A_XMLParser.t +++ b/t/A_XMLParser.t @@ -6,10 +6,6 @@ use IO::File; use File::Spec; -# The suppress-able warnings still check the global flag - -$^W = 1; - # Initialise filenames and check they're there my $XMLFile = File::Spec->catfile('t', 'test1.xml'); # t/test1.xml @@ -41,8 +37,7 @@ $ENV{XML_SIMPLE_PREFERRED_PARSER} = 'XML::Parser'; { local($SIG{__WARN__}) = \&warn_handler; - $@ = ''; - $opt = eval { XMLin('', nsexpand => 1) }; + $opt = XMLin('', nsexpand => 1); } isnt($last_warning, '', "Parsing caused warning (as expected)"); @@ -56,9 +51,8 @@ is_deeply($opt, {y => 'z'}, "Parsing was successful"); { local($SIG{__WARN__}) = \&warn_handler; - $@ = ''; $last_warning = ''; - $opt = eval { XMLin('', ParserOpts => [ ParseParamEnt => 1 ]) }; + $opt = XMLin('', ParserOpts => [ ParseParamEnt => 1 ]); } isnt($last_warning, '', "Using ParserOpts caused warning (as expected)"); @@ -70,12 +64,11 @@ is_deeply($opt, {y => 'z'}, "Parsing was successful"); # Check it doesn't happen if warnings disabled { + no warnings; local($SIG{__WARN__}) = \&warn_handler; - $@ = ''; $last_warning = ''; - local($^W) = 0; - $opt = eval { XMLin('', ParserOpts => [ ParseParamEnt => 1 ]) }; + $opt = XMLin('', ParserOpts => [ ParseParamEnt => 1 ]); } is($last_warning, '', "ParserOpts warning uppressed successfully"); @@ -85,7 +78,6 @@ is_deeply($opt, {y => 'z'}, "Parsing was successful"); # Try parsing a string -$@ = ''; $opt = eval { XMLin(q()); }; @@ -101,7 +93,6 @@ is_deeply($opt, $expected, 'matches expectations (attributes)'); # Try parsing a named external file -$@ = ''; $opt = eval{ XMLin($XMLFile); }; is($@, '', "XML::Parser didn't choke on named external file"); is_deeply($opt, { @@ -111,7 +102,6 @@ is_deeply($opt, { # Try parsing from an IO::Handle -$@ = ''; my $fh = new IO::File; $XMLFile = File::Spec->catfile('t', '1_XMLin.xml'); # t/1_XMLin.xml eval { diff --git a/t/B_Hooks.t b/t/B_Hooks.t index 9b66c2d..729a29a 100644 --- a/t/B_Hooks.t +++ b/t/B_Hooks.t @@ -12,7 +12,6 @@ SKIP: { skip "Tie::IxHash not installed", 3 if $@; - $@ = ''; eval <<'EOF'; package SimpleOrder; diff --git a/t/release-pod-syntax.t b/t/release-pod-syntax.t index d46a955..cdd6a6c 100644 --- a/t/release-pod-syntax.t +++ b/t/release-pod-syntax.t @@ -7,9 +7,8 @@ BEGIN { } } +# This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use Test::More; - -eval "use Test::Pod 1.41"; -plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; +use Test::Pod 1.41; all_pod_files_ok(); -- 2.34.1