Catmandu-XML-0.16/0000775000175000017500000000000012537517630012023 5ustar vojvojCatmandu-XML-0.16/README0000644000175000017500000000252312537517630012703 0ustar vojvojNAME Catmandu::XML - modules for handling XML data within the Catmandu framework DESCRIPTION Catmandu::XML contains modules for handling XML data within the Catmandu framework. Parsing and serializing is based on XML::LibXML with XML::Struct. XSLT transormation is based on XML::LibXSLT. MODULES Catmandu::Importer::XML Import serialized XML documents as data structures. Catmandu::Exporter::XML Serialize data structures as XML documents. Catmandu::XML::Transformer Utility module for XML/XSLT processing. Catmandu::Fix::xml_read Fix function to parse XML to MicroXML as implemented by XML::Struct. Catmandu::Fix::xml_write Fix function to seralize XML. Catmandu::Fix::xml_simple Fix function to parse XML or convert MicroXML to simple form as known from XML::Simple. Catmandu::Fix::xml_transform Fix function to transform XML using XSLT stylesheets. SEE ALSO This module requires the libraries libxml2 and libxslt. For instance on Ubuntu Linux call sudo apt-get install libxslt-dev libxml2-dev before installation of Catmandu::XML. COPYRIGHT AND LICENSE Copyright Jakob Voss, 2014- This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Catmandu-XML-0.16/cpanfile0000644000175000017500000000013512537517630013524 0ustar vojvojrequires 'Catmandu', '0.9'; requires 'XML::Struct', '0.26'; requires 'XML::LibXSLT', '1.78'; Catmandu-XML-0.16/META.yml0000644000175000017500000000155612537517630013301 0ustar vojvoj--- abstract: 'modules for handling XML data within the Catmandu framework' author: - 'Jakob Voß' build_requires: {} configure_requires: Module::Build::Tiny: '0.039' dynamic_config: 0 generated_by: 'Dist::Milla version v1.0.15, Dist::Zilla version 5.020, CPAN::Meta::Converter version 2.142690' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Catmandu-XML no_index: directory: - t - xt - inc - share - eg - examples requires: Catmandu: '0.9' XML::LibXSLT: '1.78' XML::Struct: '0.26' resources: bugtracker: https://github.com/LibreCat/Catmandu-XML/issues homepage: https://github.com/LibreCat/Catmandu-XML repository: https://github.com/LibreCat/Catmandu-XML.git version: '0.16' x_contributors: - 'Jakob Voss ' - 'Nicolas Franck ' Catmandu-XML-0.16/META.json0000644000175000017500000000304112537517630013440 0ustar vojvoj{ "abstract" : "modules for handling XML data within the Catmandu framework", "author" : [ "Jakob Voß" ], "dynamic_config" : 0, "generated_by" : "Dist::Milla version v1.0.15, Dist::Zilla version 5.020, CPAN::Meta::Converter version 2.142690", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Catmandu-XML", "no_index" : { "directory" : [ "t", "xt", "inc", "share", "eg", "examples" ] }, "prereqs" : { "configure" : { "requires" : { "Module::Build::Tiny" : "0.039" } }, "develop" : { "requires" : { "Dist::Milla" : "v1.0.15", "Test::Pod" : "1.41" } }, "runtime" : { "requires" : { "Catmandu" : "0.9", "XML::LibXSLT" : "1.78", "XML::Struct" : "0.26" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/LibreCat/Catmandu-XML/issues" }, "homepage" : "https://github.com/LibreCat/Catmandu-XML", "repository" : { "type" : "git", "url" : "https://github.com/LibreCat/Catmandu-XML.git", "web" : "https://github.com/LibreCat/Catmandu-XML" } }, "version" : "0.16", "x_contributors" : [ "Jakob Voss ", "Nicolas Franck " ] } Catmandu-XML-0.16/t/0000775000175000017500000000000012537517630012266 5ustar vojvojCatmandu-XML-0.16/t/example.xml0000644000175000017500000000020212537517630014433 0ustar vojvoj foo bar baz Catmandu-XML-0.16/t/release-pod-syntax.t0000644000175000017500000000045612537517630016202 0ustar vojvoj#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use Test::More; use Test::Pod 1.41; all_pod_files_ok(); Catmandu-XML-0.16/t/transform3.xsl0000644000175000017500000000034612537517630015115 0ustar vojvoj Catmandu-XML-0.16/t/transform2.xsl0000644000175000017500000000045012537517630015110 0ustar vojvoj DOC: Catmandu-XML-0.16/t/doc.xml0000644000175000017500000000015712537517630013556 0ustar vojvoj Welcome!

Look at my homepage!

Catmandu-XML-0.16/t/importer.t0000644000175000017500000000577112537517630014324 0ustar vojvojuse strict; use warnings; use Test::More; use_ok('Catmandu::Importer::XML'); sub check_import(@) { my $options = shift; my $file = shift; my $importer = Catmandu::Importer::XML->new(file => $file, %$options); my $data = $importer->to_array; is_deeply $data, @_; } check_import { }, \"content" => [ { element => 'content' } ], 'simple'; check_import { type => 'ordered' }, \"content" => [ [ root => { x => 1 }, [ [ element => { } , [ 'content' ] ] ] ] ], 'ordered'; my $xml = <<'XML'; foo bar baz XML check_import { }, \$xml => [ { attr => 'value', field1 => [ 'foo', 'bar' ], field2 => { 'doz' => 'baz' }, } ], 'simple'; check_import { type => 'ordered', attributes => 1 }, \$xml => [ [ doc => { attr => "value" }, [ [ field1 => { }, ["foo"] ], [ field1 => { }, ["bar"] ], [ field2 => { }, [ [ doz => { }, ["baz"] ] ] ] ] ] ], 'ordered with attributes'; check_import { type => 'ordered', attributes => 0 }, \$xml => [ [ doc => [ [ field1 => ["foo"] ], [ field1 => ["bar"] ], [ field2 => [ [ doz => ["baz"] ] ] ] ] ] ], 'ordered without attributes'; check_import { type => 'simple', depth => 2 }, \$xml => [ { attr => 'value', field1 => [ 'foo', 'bar' ], field2 => { doz => [ [ doz => { }, ["baz"] ] ] } } ], 'simple with depth=2'; check_import { type => 'simple' }, "t/input.xml" => [ { id => [1,2,4], xx => 3 } ], 'simple'; check_import { root => 1, attributes => 0 }, "t/input.xml" => [ { doc => { id => [1,2,4], xx => 3 } } ], 'simple without attributes, with root'; check_import { type => 'simple', path => '/*/id' }, "t/input.xml" => [ { id => 1 }, { id => 2 }, { id => 4 } ], 'multiple entries (root included by default)'; check_import { type => 'simple', path => '/*/id', root => 0 }, "t/input.xml" => [ { id => 1 }, { id => 2 }, { id => 4 } ], 'multiple entries (root option ignored)'; check_import { type => 'simple', path => '/*/id', root => 'n' }, "t/input.xml" => [ { n => 1 }, { n => 2 }, { n => 4 } ], 'multiple entries (simple)'; check_import { type => 'simple', path => 'doc', xslt => 't/transform3.xsl' }, "t/collection.xml" => [ { doz => 1 }, { doz => 2 }, { doz => 3 } ], 'import with transformation'; my $warn; $SIG{__WARN__} = sub { $warn = shift }; check_import { type => 'simple', path => 'doc', transform => 't/transform3.xsl' }, "t/collection.xml" => [ { doz => 1 }, { doz => 2 }, { doz => 3 } ], 'import with transformation (deprecated option)'; ok $warn, "deprecated option"; done_testing; Catmandu-XML-0.16/t/Catmandu-XML-Transformer.t0000644000175000017500000000251312537517630017144 0ustar vojvojuse strict; use warnings; use Test::More; use Catmandu::XML::Transformer; use XML::LibXML; my $transformer = Catmandu::XML::Transformer->new( stylesheet => 't/transform1.xsl' ); is_deeply $transformer->stylesheet, ['t/transform1.xsl'], 'stylesheet'; is $transformer->output_format, undef, 'output_format'; is $transformer->transform( '' ), "\nbar\n", 'xml_string'; my $xml_dom = XML::LibXML->load_xml(string => ''); my $result = $transformer->transform($xml_dom); isa_ok $result, 'XML::LibXML::Document'; is $result, "\nbar\n", 'xml_dom'; $xml_dom = XML::LibXML->load_xml('string','')->documentElement; isa_ok $transformer->transform($xml_dom), 'XML::LibXML::Document'; is_deeply $transformer->transform( [ doc => { attr => "bar" }, [ ] ] ), [ 'foo', {}, [ 'bar' ] ], 'xml_struct'; is_deeply $transformer->transform( { doc => 0 } ), { foo => {} }, 'xml_simple'; $transformer = Catmandu::XML::Transformer->new( stylesheet => 't/transform2.xsl' ); is $transformer->output_format, 'string', 'output method=text'; $transformer = Catmandu::XML::Transformer->new( stylesheet => 't/transform1.xsl', output_format => 'DOM', ); is $transformer->output_format, 'dom', 'normalize output_format'; done_testing; Catmandu-XML-0.16/t/transform1.xsl0000644000175000017500000000036012537517630015107 0ustar vojvoj Catmandu-XML-0.16/t/xml_simple.t0000644000175000017500000000076212537517630014627 0ustar vojvojuse strict; use warnings; use Test::More; use Catmandu::Fix::xml_simple as => 'simple'; my $xml = 'xyz'; my $data = { xml => $xml }; simple($data,'xml'); is_deeply $data->{xml}, { a => [qw(x y z)] }, 'parse with xml_simple'; # TODO: include attributes $xml = [ root => {}, [[a=>{},['x']],[a=>{},['y']],[a=>{},['z']] ] ]; $data = { xml => $xml }; simple($data,'xml'); is_deeply $data, { xml => { a => [qw(x y z)] } }, 'transform with xml_simple'; done_testing; Catmandu-XML-0.16/t/xml_transform.t0000644000175000017500000000303412537517630015344 0ustar vojvojuse strict; use warnings; use Test::More; use Catmandu::Fix::xml_transform as => 'transform'; my ($xml, $struct) = ('', [ doc => { attr => "bar" }, [ ] ]); my $data = { xml => $xml }; transform($data,'xml', file => 't/transform1.xsl'); is $data->{xml}, "\nbar\n", 'xml_transform string'; $data = { xml => $struct }; transform($data,'xml', file => 't/transform1.xsl'); is_deeply $data->{xml}, [ foo => { }, ['bar'] ], 'xml_transform struct'; $data = { xml => $struct }; transform($data,'xml', file => 't/transform1.xsl', format => 'string'); is $data->{xml}, "\nbar\n", 'format=string'; $data = { xml => $xml }; transform($data,'xml', file => 't/transform2.xsl'); is $data->{xml}, 'DOC: bar', 'xsl:output method=text (string)'; $data = { xml => $struct }; transform($data,'xml', file => 't/transform2.xsl'); is $data->{xml}, 'DOC: bar', 'xsl:output method=text (struct)'; $data = { xml => $struct }; transform($data,'xml', file => [] ); is_deeply $data, { xml => $struct }, 'empty transformation (struct)'; $data = { xml => $xml }; transform($data,'xml', file => [] ); is_deeply $data, { xml => "\n$xml\n" }, 'empty transformation (string)'; foreach my $pipeline ( 't/transform1.xsl,t/transform3.xsl', [qw(t/transform1.xsl t/transform3.xsl)] ) { $data = { xml => $struct }; transform($data,'xml', file => $pipeline); is_deeply $data, { xml => [ doz => { }, ['bar'] ] }, 'transformation pipeline'; } done_testing; Catmandu-XML-0.16/t/exporter.t0000644000175000017500000000274512537517630014331 0ustar vojvojuse strict; use warnings; use Test::More; use XML::Struct::Writer; use_ok('Catmandu::Exporter::XML'); my $out = ""; my $exporter = Catmandu::Exporter::XML->new( file => \$out ); $exporter->add( [ foo => { bar => 'doz' }, ['&'] ] ); is $exporter->count, 1, 'count'; $exporter->add( [ foo => {}, ['<'] ] ); is $exporter->count, 2, 'count'; my $xml = < & < XML is $out, $xml, 'export multiple documents'; $out = ""; $exporter = Catmandu::Exporter::XML->new( attributes => 0, pretty => 1, xmldecl => 0, file => \$out ); $exporter->add( [ foo => [ [ bar => ['doz'] ] ] ] ); $xml = < doz XML is $out, $xml, 'export with configuration'; $out = ""; $exporter = Catmandu::Exporter::XML->new( file => \$out, xmldecl => 0, field => 'xml' ); $exporter->add( { xml => [ foo => { bar => 23 } ] } ); is $out, "\n", 'export from field'; use File::Temp qw(tempdir); my $dir = tempdir(); $exporter = Catmandu::Exporter::XML->new( directory => $dir, field => '_xml' ); $exporter->add_many([ { _id => 'foo', _xml => [ foo => {} ] }, { _id => 'bar.xml', _xml => [ bar => {} ] }, ]); ok(-e "$dir/foo.xml" and -e "$dir/bar.xml", 'export to directory'); $xml = "\n\n"; $out = do { local (@ARGV, $/) = "$dir/foo.xml"; <> }; is $out, $xml, 'exported to multiple files'; done_testing; Catmandu-XML-0.16/t/xml_write.t0000644000175000017500000000113412537517630014462 0ustar vojvojuse strict; use warnings; use Test::More; use Catmandu::Fix::xml_write as => 'serialize'; my $xml = [ 'foo', { bar => 'doz' }, [ 'baz' ] ]; my $data = { xml => [ 'foo', { bar => 'doz' }, [ 'baz' ] ] }; serialize($data,'xml'); is_deeply $data->{xml}, "\nbaz\n", 'xml_write'; $data = { xml => [ foo => [ [ bar => ['doz'] ] ] ] }; serialize($data,'xml', attributes => 0, pretty => 1, xmldecl => 0); is_deeply $data->{xml}, < doz XML done_testing; Catmandu-XML-0.16/t/xml_read.t0000644000175000017500000000133212537517630014243 0ustar vojvojuse strict; use warnings; use Test::More; use Catmandu::Fix::xml_read as => 'parse'; my $xml = 'baz'; my $data = { xml => $xml }; parse($data,'xml'); is_deeply $data->{xml}, [ 'foo', { bar => 'doz' }, [ 'baz' ] ], 'xml_read'; $data = { xml => $xml }; parse($data,'xml', attributes=> 0); is_deeply $data->{xml}, [ 'foo', [ 'baz' ] ], 'xml_read(attributes=0)'; $xml = 'xyz'; $data = { xml => $xml }; parse($data,'xml', simple => 1); is_deeply $data->{xml}, { a => [qw(x y z)] }, 'xml_read(simple=0)'; $data = { xml => $xml }; parse($data,'xml', attributes => 0, path => 'a'); is_deeply $data->{xml}, [[a=>['x']],[a=>['y']],[a=>['z']] ], 'xml_read(path=a)'; done_testing; Catmandu-XML-0.16/t/collection.xml0000644000175000017500000000021012537517630015132 0ustar vojvoj 1 2 3 Catmandu-XML-0.16/t/input.xml0000644000175000017500000000012712537517630014145 0ustar vojvoj 1 2 3 4 Catmandu-XML-0.16/Changes0000644000175000017500000000253312537517630013317 0ustar vojvojChangelog for Catmandu-XML 0.16 2015-06-15 11:49:10 CEST - fixed failing importer tests - additional xml_transform option 'format' - Catmandu::Importer::XML option 'transform' renamed to 'xslt' 0.15 2015-05-13 20:16:05 CEST - improved Catmandu::XML::Transformer - migrated to Milla 0.14 2014-07-07T13:17:44 - improved XSLT transformation - documentation 0.13 2014-06-30T08:53:24 - fixed exporter option 'field' 0.12 2014-06-30T08:41:45 - make exporter option 'field' optional - support XSLT pipelines (issue dist.ini) - support 0.11 2014-06-29T15:35:52 - fixed issue #11 0.10 2014-06-25T07:15:12 - fixed dependencies 0.09 2014-06-24T20:39:57 - implemented XML Exporter (issue #9) 0.08 2014-06-24T10:06:10 - added fix xml_simple 0.07 2014-06-23T06:07:35 - new option xmldecl to xml_write 0.06 2014-06-20T11:20:56 - added fix xml_write 0.05 2014-06-20T09:40:48 - added fix xml_read 0.04 2014-06-19T08:54:35 - support transformation of MicroXML - new fix xml_transform - merged package from Catmandu::Fix::XML (Nicolas Franck) 0.03 2013-09-19T07:04:53 - added reader options 'ns' and 'depth' 0.02 2013-09-12T09:11:51 - include root element by default if path is set 0.01 2013-09-11T12:19:11 - documentation - based on XML::Struct 0.10 - fixed dependencies - support ordered XML - initial draft Catmandu-XML-0.16/Makefile.PL0000644000175000017500000000207212537517630013774 0ustar vojvoj # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.019. use strict; use warnings; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "Modules for handling XML data within the Catmandu framework", "AUTHOR" => "Jakob Vo\x{df}", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30" }, "DISTNAME" => "Catmandu-XML", "EXE_FILES" => [], "LICENSE" => "perl", "NAME" => "Catmandu::XML", "PREREQ_PM" => { "Catmandu" => "0.9", "XML::LibXSLT" => "1.78", "XML::Struct" => "0.23" }, "VERSION" => "0.13", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Catmandu" => "0.9", "XML::LibXSLT" => "1.78", "XML::Struct" => "0.23" ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); Catmandu-XML-0.16/LICENSE0000644000175000017500000004361712537517630013041 0ustar vojvojThis software is copyright (c) 2014- by -. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2014- by -. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes 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 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 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 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 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 free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2014- by -. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Catmandu-XML-0.16/Build.PL0000644000175000017500000000025712537517630013321 0ustar vojvoj# This Build.PL for Catmandu-XML was generated by Dist::Zilla::Plugin::ModuleBuildTiny 0.010. use strict; use warnings; use 5.006; use Module::Build::Tiny 0.039; Build_PL(); Catmandu-XML-0.16/lib/0000775000175000017500000000000012537517630012571 5ustar vojvojCatmandu-XML-0.16/lib/Catmandu/0000775000175000017500000000000012537517630014325 5ustar vojvojCatmandu-XML-0.16/lib/Catmandu/Importer/0000775000175000017500000000000012537517630016126 5ustar vojvojCatmandu-XML-0.16/lib/Catmandu/Importer/XML.pm0000644000175000017500000001023612537517630017124 0ustar vojvojpackage Catmandu::Importer::XML; our $VERSION = '0.16'; use namespace::clean; use Catmandu::Sane; use Moo; use XML::Struct::Reader; use Catmandu::XML::Transformer; with 'Catmandu::Importer'; has type => (is => 'ro', default => sub { 'simple' }); has path => (is => 'ro'); has root => (is => 'lazy', default => sub { defined $_[0]->path ? 1 : 0 }); has depth => (is => 'ro'); has ns => (is => 'ro', default => sub { '' }); has attributes => (is => 'ro', default => sub { 1 }); has whitespace => (is => 'ro', default => sub { 0 }); has xslt => ( is => 'ro', lazy => 1, coerce => sub { Catmandu::XML::Transformer->new( stylesheet => $_[0] ) if defined $_[0] }, builder => sub { $_[0]->transform } ); has transform => ( is => 'ro', coerce => sub { warn "Catmandu::Importer::XML option 'transform' renamed to 'xslt'\n"; $_[0]; } ); sub generator { my ($self) = @_; sub { state $reader = do { my %options = ( from => ($self->file || $self->fh), whitespace => $self->whitespace, attributes => $self->attributes, depth => $self->depth, ns => $self->ns, ); $options{path} = $self->path if defined $self->path; if ($self->type eq 'simple') { $options{simple} = 1; $options{root} = $self->root; } elsif ($self->type ne 'ordered') { return; } XML::Struct::Reader->new(%options); }; my $item = $reader->readNext; # TODO: transformation should be done earlier for efficiency # and because simple format modifies the XML document (bug) return $self->xslt ? $self->xslt->transform($item) : $item } } 1; __END__ =head1 NAME Catmandu::Importer::XML - Import serialized XML documents =head1 DESCRIPTION This L reads XML and transforms it into a data structure. See L, L, L and L for methods and options derived from these modules. The importer can also be used internally for custom importers that need to parse XML data. =head1 CONFIGURATION =over =item type By default (type "C"), elements and attributes and converted to keys in a key-value structure. For instance this document: foo bar baz is imported as { attr => 'value', field1 => [ 'foo', 'bar' ], field2 => { 'doz' => 'baz' }, } With type "C" elements are preserved in the order of their appereance. For instance the sample document above is imported as: [ doc => { attr => "value" }, [ [ field1 => { }, ["foo"] ], [ field1 => { }, ["bar"] ], [ field2 => { }, [ [ doz => { }, ["baz"] ] ] ] ] ] =item depth Maximum depth for type "C". For instance with depth 1, the sample document above would be imported as: { attr => 'value', field1 => [ 'foo', 'bar' ], field2 => { doz => [ [ doz => { }, ["baz"] ] ] } } =item attributes Include XML attributes. Enabled by default. =item path Path expression to select XML elements. If not set the root element is selected. =item root Include root element name for type C. Disabled by default. The option is ignored if type is not C or if a C has explicitly been set. =item ns Set to C for stripping namespace prefixes and xmlns-attributes. =item whitespace Include ignoreable whitespace. Disabled by default. =item xslt Optional (list of) XSLT stylesheets to process records with L. =item transform Deprecated alias for option C. =back =head1 SEE ALSO This module is just a thin layer on top of L. Have a look at L to implement Importers and Exporters for more specific XML-based data formats. =cut =encoding utf8 Catmandu-XML-0.16/lib/Catmandu/XML.pm0000644000175000017500000000351512537517630015325 0ustar vojvojpackage Catmandu::XML; our $VERSION = '0.16'; __END__ =head1 NAME Catmandu::XML - modules for handling XML data within the Catmandu framework =begin markdown # Status [![Build Status](https://travis-ci.org/LibreCat/Catmandu-XML.png)](https://travis-ci.org/LibreCat/Catmandu-XML) [![Coverage Status](https://coveralls.io/repos/LibreCat/Catmandu-XML/badge.png)](https://coveralls.io/r/LibreCat/Catmandu-XML) [![Kwalitee Score](http://cpants.cpanauthors.org/dist/Catmandu-XML.png)](http://cpants.cpanauthors.org/dist/Catmandu-XML) =end markdown =head1 DESCRIPTION L contains modules for handling XML data within the L framework. Parsing and serializing is based on L with L. XSLT transormation is based on L. =head1 MODULES =over 4 =item L Import serialized XML documents as data structures. =item L Serialize data structures as XML documents. =item L Utility module for XML/XSLT processing. =item L Fix function to parse XML to MicroXML as implemented by L. =item L Fix function to seralize XML. =item L Fix function to parse XML or convert MicroXML to simple form as known from L. =item L Fix function to transform XML using XSLT stylesheets. =back =head1 SEE ALSO This module requires the libraries C and C. For instance on Ubuntu Linux call C before installation of Catmandu::XML. =encoding utf8 =head1 COPYRIGHT AND LICENSE Copyright Jakob Voss, 2014- This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Catmandu-XML-0.16/lib/Catmandu/Exporter/0000775000175000017500000000000012537517630016135 5ustar vojvojCatmandu-XML-0.16/lib/Catmandu/Exporter/XML.pm0000644000175000017500000000524212537517630017134 0ustar vojvojpackage Catmandu::Exporter::XML; our $VERSION = '0.16'; use Catmandu::Sane; use Moo; use XML::Struct::Writer; use Catmandu::Util qw(io); with 'Catmandu::Exporter'; has directory => ( is => 'ro', isa => sub { die "output directory not found\n" unless -d $_[0] }, ); has field => ( is => 'ro', lazy => 1, ); has filename => ( is => 'ro', lazy => 1, default => sub { defined $_[0]->directory ? '_id' : undef } ); our @WRITER_OPTIONS; BEGIN { @WRITER_OPTIONS = qw(attributes xmldecl encoding version standalone pretty); has $_ => (is => 'rw') for @WRITER_OPTIONS; } has writer => ( is => 'ro', predicate => 1, lazy => 1, default => sub { XML::Struct::Writer->new( to => $_[0]->fh, map { $_ => $_[0]->$_ } grep { defined $_[0]->$_ } @WRITER_OPTIONS ); }, ); sub add { my ($self, $data) = @_; my $xml = defined $self->field ? $data->{$self->field} : $data; if (defined $self->directory) { my $filename = $data->{$self->filename}; $filename .= '.xml' if $filename !~ /\.xml/; if ($filename !~ qr{^[^/\0]+$}) { $self->log->error("disallowed filename: $filename"); # TODO: check for disallowed characters on non-Unix systems return; } else { my $filename = $self->directory . "/$filename"; $self->log->debug("exporting XML to $filename"); $self->writer->handler->{fh} = io( $filename, mode => 'w' ); # TODO: binmode => $self->writer->encoding // ':utf8' $self->writer->write($xml); $self->writer->handler->fh->close; } } else { $self->writer->write($xml); } } 1; __END__ =head1 NAME Catmandu::Exporter::XML - serialize and export XML documents =head1 DESCRIPTION This L exports items serialized as XML. Serialization is implemented based on L. By default, each item is written to STDOUT. =head1 CONFIGURATION =over =item attributes =item xmldecl =item encoding =item version =item standalone =item pretty These options are passed to L. The target (option C) is based on L's option C or C. =item field Take XML from a given field of each item, e.g. field C as following: { xml => [ root => { xmlns => 'http://example.org/' }, [ ... ] ] } =item directory Serialize to multiple files in a given directory. =item filename Field to take filenames from if option C is set. Defaults to C<_id>. The file extension C<.xml> is appended unless given. =back =cut Catmandu-XML-0.16/lib/Catmandu/XML/0000775000175000017500000000000012537517630014765 5ustar vojvojCatmandu-XML-0.16/lib/Catmandu/XML/Transformer.pm0000644000175000017500000000726412537517630017634 0ustar vojvojpackage Catmandu::XML::Transformer; our $VERSION = '0.16'; use Catmandu::Sane; use Moo; use Carp; use XML::LibXML; use XML::LibXSLT; use Scalar::Util qw(blessed reftype); use XML::Struct::Reader; use XML::Struct::Writer; has stylesheet => ( is => 'ro', coerce => sub { ref $_[0] // '' eq 'ARRAY' ? $_[0] : [ split /,/, $_[0] ] }, default => sub { [] } ); has output_format => ( is => 'ro', coerce => sub { defined $_[0] ? lc $_[0] : undef } ); has process => ( is => 'lazy', builder => sub { [ map { XML::LibXSLT->new()->parse_stylesheet( XML::LibXML->load_xml(location => $_, no_cdata=>1) ) } @{$_[0]->stylesheet} ] } ); sub BUILD { if (@{$_[0]->process} and $_[0]->process->[-1]->output_method eq 'text') { $_[0]->{output_format} = 'string'; } } sub transform { my ($self, $xml) = @_; my ($format, $result); return if !defined $xml; if (blessed $xml) { if ($xml->isa('XML::LibXML::Document') or $xml->isa('XML::LibXML::Element')) { $format = 'dom'; } else { croak "Cannot convert ".ref($xml)." to XML"; } } elsif (ref $xml) { if (reftype $xml eq 'ARRAY') { $format = 'struct'; $xml = XML::Struct::Writer->new->write($xml); } else { $format = 'simple'; $xml = XML::Struct::Writer->new(simple => 1)->write($xml); } } else { $format = 'string'; $xml = XML::LibXML->load_xml(string => $xml); } $format = $self->output_format if $self->output_format; if (@{$self->process}) { foreach (@{$self->process}) { $xml = $_->transform($xml); } } if ($format eq 'string') { if ($self->process->[-1]) { return $self->process->[-1]->output_as_chars($xml); } else { return $xml->toString; } } elsif ($format eq 'struct') { return XML::Struct::Reader->new( from => $xml )->readDocument; } elsif ($format eq 'simple') { my $reader = XML::Struct::Reader->new( from => $xml, simple => 1, root => 1 ); return $reader->readDocument; } else { return $xml; } } 1; __END__ =head1 NAME Catmandu::XML::Transformer - Utility module for XML/XSLT processing =cut =head1 SYNOPISIS $transformer = Catamandu::XML::Transformer->new( stylesheet => 'file.xsl' ); $xml_string = $transformer->transform( $xml_string ); # SCALAR $xml_dom = $transformer->transform( $xml_dom ); # XML::LibXML::Document $xml_struct = $transformer->transform( $xml_struct ); # ARRAY reference $xml_simple = $transformer->transform( $xml_simple ); # HASH reference $transformer = Catamandu::XML::Transformer->new( output_format => 'string' ); $xml_string = $transformer->transform( $xml ); # any XML to SCALAR =head1 CONFIGURATION =over =item stylesheet Zero or more XSLT files given as comma-separated list of files or array reference with multiple files to apply as transformation pipeline. Files are parsed once on instantiation of the Catmandu::XML::Transformer object. =item output_format Expected output format C, C, C, C. By default the input format triggers the output format. If the last stylesheet has text output (C<< >>) then output format is automatically set to C. =back =head1 METHODS =over =item stylesheet() Returns an array reference of XSLT filenames used as transformation pipeline. =item output_format() Returns the output format or C. =back =head1 SEE ALSO L =cut Catmandu-XML-0.16/lib/Catmandu/Fix/0000775000175000017500000000000012537517630015053 5ustar vojvojCatmandu-XML-0.16/lib/Catmandu/Fix/xml_write.pm0000644000175000017500000000406212537517630017423 0ustar vojvojpackage Catmandu::Fix::xml_write; our $VERSION = '0.16'; use Catmandu::Sane; use Moo; use XML::Struct::Writer; use XML::LibXML::Reader; use Catmandu::Fix::Has; with 'Catmandu::Fix::Base'; has field => (fix_arg => 1); has attributes => (fix_opt => 1); has pretty => (fix_opt => 1); has encoding => (fix_opt => 1, default => sub { 'UTF-8' }); has version => (fix_opt => 1); has standalone => (fix_opt => 1); has xmldecl => (fix_opt => 1, default => sub { 1 }); has _writer => ( is => 'ro', lazy => 1, builder => sub { XML::Struct::Writer->new( map { $_ => $_[0]->$_ } grep { defined $_[0]->$_ } qw(attributes pretty encoding version standalone xmldecl) ); } ); sub emit { my ($self,$fixer) = @_; my $path = $fixer->split_path($self->field); my $key = pop @$path; my $writer = $fixer->capture($self->_writer); my $pretty = $fixer->capture($self->pretty); return $fixer->emit_walk_path($fixer->var,$path,sub{ my $var = $_[0]; $fixer->emit_get_key($var,$key,sub{ my $var = $_[0]; return "${var} = (ref(${var}) =~ 'XML::LibXML::Document=')" . "? ${var}->serialize(${pretty}) : do {". "my \$s=''; ${writer}->to(\\\$s); ${writer}->write(${var}); \$s" . "}"; }); }); } 1; __END__ =head1 NAME Catmandu::Fix::xml_write - serialize XML =head1 SYNOPSIS # serialize XML structure given in field 'xml' xml_write(xml) xml_write(xml, pretty: 1) =head1 DESCRIPTION This L serializes XML documents (given in MicroXML form as used by L or as instance of L). In short, this is a wrapper around L. =head1 CONFIGURATION =over =item attributes Set to false to not expect attribute hashes in the XML structure. =item pretty Pretty-print XML if set to C<1>. =item xmldecl =item version =item encoding =item standalone =back =head1 SEE ALSO L =cut Catmandu-XML-0.16/lib/Catmandu/Fix/xml_simple.pm0000644000175000017500000000425212537517630017563 0ustar vojvojpackage Catmandu::Fix::xml_simple; our $VERSION = '0.16'; use Catmandu::Sane; use Moo; use XML::Struct::Reader; use XML::LibXML::Reader; use Catmandu::Fix::Has; with 'Catmandu::Fix::Base'; # TODO: avoid code duplication with xml_read has field => (fix_arg => 1); has attributes => (fix_opt => 1); has ns => (fix_opt => 1); has content => (fix_opt => 1); has root => (fix_opt => 1); has depth => (fix_opt => 1); has path => (fix_opt => 1); has whitespace => (fix_opt => 1); sub simple { 1 } has _reader => ( is => 'ro', lazy => 1, builder => sub { XML::Struct::Reader->new( map { $_ => $_[0]->$_ } grep { defined $_[0]->$_ } qw(attributes ns simple root depth content whitespace) ); } ); sub emit { my ($self,$fixer) = @_; my $path = $fixer->split_path($self->field); my $key = pop @$path; my $reader = $fixer->capture($self->_reader); my $xpath = $fixer->capture($self->path); my $attributes = $fixer->capture($self->attributes); # TODO: use XML::Struct::Simple instead my $options = $fixer->capture({ map { $_ => $self->$_ } grep { defined $self->$_ } qw(root depth attributes) }); return $fixer->emit_walk_path($fixer->var,$path,sub{ my $var = $_[0]; $fixer->emit_get_key($var,$key,sub{ my $var = $_[0]; return <new( string => ${var} ); ${var} = ${xpath} ? [ ${reader}->readDocument(\$stream, ${xpath}) ] : ${reader}->readDocument(\$stream); } PERL }); }); } 1; __END__ =head1 NAME Catmandu::Fix::xml_simple - parse/convert XML to simple form =head1 SYNOPSIS xml_read(xml) xml_simple(xml) xml_read(xml, simple=1) # equivalent =head1 DESCRIPTION This L transforms MicroXML or parses XML strings simple XML with L. =head1 OPTIONS See L for parsing options. =cut Catmandu-XML-0.16/lib/Catmandu/Fix/xml_read.pm0000644000175000017500000000524612537517630017211 0ustar vojvojpackage Catmandu::Fix::xml_read; our $VERSION = '0.16'; use Catmandu::Sane; use Moo; use XML::Struct::Reader; use XML::LibXML::Reader; use Catmandu::Fix::Has; with 'Catmandu::Fix::Base'; has field => (fix_arg => 1); has attributes => (fix_opt => 1); has ns => (fix_opt => 1); has content => (fix_opt => 1); has simple => (fix_opt => 1); has root => (fix_opt => 1); has depth => (fix_opt => 1); has path => (fix_opt => 1); has whitespace => (fix_opt => 1); has _reader => ( is => 'ro', lazy => 1, builder => sub { XML::Struct::Reader->new( map { $_ => $_[0]->$_ } grep { defined $_[0]->$_ } qw(attributes ns simple root depth content whitespace) ); } ); sub emit { my ($self,$fixer) = @_; my $path = $fixer->split_path($self->field); my $key = pop @$path; my $reader = $fixer->capture($self->_reader); my $xpath = $fixer->capture($self->path); return $fixer->emit_walk_path($fixer->var,$path,sub{ my $var = $_[0]; $fixer->emit_get_key($var,$key,sub{ my $var = $_[0]; return "my \$stream = XML::LibXML::Reader->new( string => ${var} );". "${var} = ${xpath} ? [ ${reader}->readDocument(\$stream, ${xpath}) ] " . ": ${reader}->readDocument(\$stream);"; }); }); } 1; __END__ =head1 NAME Catmandu::Fix::xml_read - parse XML to MicroXML =head1 SYNOPSIS # parse XML string given in field 'xml' xml_read(xml) xml_read(xml, simple: 1) xml_read(xml, attributes: 0) =head1 DESCRIPTION This L parses XML strings into MicroXML or simple XML with L. =head1 CONFIGURATION Parsing can be configured with the following options of L: =over =item attributes Include XML attributes (enabled by default) =item ns Define processing of XML namespaces (C by default) =item whitespace Include ignorable whitespace as text elements (disabled by default) =item simple Convert to simple key-value structure, as known from L =item root Keep (and possibly rename) root element when converting to C form =item depth Only transform to a given depth with option C =item path Parse only given elements (and all of its child elements) and return as array. For instance C<< path => "p" >> in an XHTML document would return a list of parsed paragraphs (C<<

...

>>). This option overrides option C. =item content Name of text content when converting to C form =back =head1 SEE ALSO L, L L =cut Catmandu-XML-0.16/lib/Catmandu/Fix/xml_transform.pm0000644000175000017500000000345212537517630020306 0ustar vojvojpackage Catmandu::Fix::xml_transform; our $VERSION = '0.16'; use Catmandu::Sane; use Moo; use Catmandu::Fix::Has; use Catmandu::XML::Transformer; with 'Catmandu::Fix::Base'; has field => (fix_arg => 1); has file => (fix_opt => 1); has format => (fix_opt => 1); has _transformer => ( is => 'ro', lazy => 1, default => sub { Catmandu::XML::Transformer->new( stylesheet => $_[0]->file, output_format => $_[0]->format, ); } ); sub emit { my ($self,$fixer) = @_; my $path = $fixer->split_path($self->field()); my $key = pop @$path; my $transformer = $fixer->capture($self->_transformer); return $fixer->emit_walk_path($fixer->var,$path,sub{ my $var = $_[0]; $fixer->emit_get_key($var,$key,sub{ my $var = $_[0]; return "${var} = ${transformer}->transform(${var});"; }); }); } 1; __END__ =head1 NAME Catmandu::Fix::xml_transform - transform XML using XSLT stylesheet =head1 SYNOPSIS # Transforms the 'xml' from marcxml to dublin core xml xml_transform('xml',file => 'marcxml2dc.xsl'); =head1 DESCRIPTION This L transforms XML with an XSLT stylesheet. Based on L the fix will transform and XML string into an XML string, MicroXML (L) into MicroXML, and a DOM into a DOM. If the stylesheet is intented to emit text (C<< >>, however, this fix I transforms produces a string. One ore multiple XSLT scripts can be specified with argument C. =head1 CONFIGURATION =over =item field Data field to get XML from =item file One or more file names of optional XSLT scripts =item format Optional output format (C, C, C, or C) =back =cut Catmandu-XML-0.16/dist.ini0000644000175000017500000000003312537517630013461 0ustar vojvojauthor=Jakob Voß [@Milla] Catmandu-XML-0.16/MANIFEST0000644000175000017500000000120712537517630013152 0ustar vojvoj# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.020. Build.PL Changes LICENSE MANIFEST META.json META.yml Makefile.PL README cpanfile dist.ini lib/Catmandu/Exporter/XML.pm lib/Catmandu/Fix/xml_read.pm lib/Catmandu/Fix/xml_simple.pm lib/Catmandu/Fix/xml_transform.pm lib/Catmandu/Fix/xml_write.pm lib/Catmandu/Importer/XML.pm lib/Catmandu/XML.pm lib/Catmandu/XML/Transformer.pm t/Catmandu-XML-Transformer.t t/collection.xml t/doc.xml t/example.xml t/exporter.t t/importer.t t/input.xml t/release-pod-syntax.t t/transform1.xsl t/transform2.xsl t/transform3.xsl t/xml_read.t t/xml_simple.t t/xml_transform.t t/xml_write.t