| 1 | #!perl |
| 2 | |
| 3 | use strictscip-perl cpan Catmandu-XSD 0.05 strict/; |
| 4 | use warningsscip-perl cpan Catmandu-XSD 0.05 warnings/; |
| 5 | use Test::Morescip-perl cpan Catmandu-XSD 0.05 Test/More/; |
| 6 | |
| 7 | use Catmanduscip-perl cpan Catmandu-XSD 0.05 Catmandu/; |
| 8 | use Catmandu::Utilscip-perl cpan Catmandu-XSD 0.05 Catmandu/Util/ qw(:io); |
| 9 | use XML::LibXMLscip-perl cpan Catmandu-XSD 0.05 XML/LibXML/; |
| 10 | use XML::LibXML::XPathContextscip-perl cpan Catmandu-XSD 0.05 XML/LibXML/XPathContext/; |
| 11 | |
| 12 | BEGIN { |
| 13 | use_okscip-perl cpan Catmandu-XSD 0.05 main/use_ok(). 'Catmandu::Exporter::XSD'; |
| 14 | } |
| 15 | |
| 16 | require_okscip-perl cpan Catmandu-XSD 0.05 main/require_ok(). 'Catmandu::Exporter::XSD'; |
| 17 | |
| 18 | { |
| 19 | my $xml = ''; |
| 20 | my $exporter = Catmandu->exporterscip-perl cpan Catmandu-XSD 0.05 Catmandu/exporter().('XSD' , |
| 21 | file => \$xml , |
| 22 | root => '{}shiporder' , |
| 23 | schemas => 't/demo/order/*.xsd' , |
| 24 | ); |
| 25 | |
| 26 | okscip-perl cpan Catmandu-XSD 0.05 main/ok(). $exporter , 'got an exporter' ; |
| 27 | |
| 28 | okscip-perl cpan Catmandu-XSD 0.05 main/ok(). $exporter->addscip-perl cpan Catmandu-XSD 0.05 Catmandu/add().({ |
| 29 | orderid => 889924 , |
| 30 | orderperson => 'Olga Brown' , |
| 31 | shipto => { |
| 32 | name => 'Kalevia Aho' , |
| 33 | address => 'Monstreet 3' , |
| 34 | city => '9000 Emarald' , |
| 35 | country => 'Canada' , |
| 36 | date => '2014-11-03' |
| 37 | } , |
| 38 | item => { |
| 39 | title => 'Empire Burlesque' , |
| 40 | note => 'Special Edition' , |
| 41 | quantity => 1 , |
| 42 | price => 10.90 |
| 43 | } |
| 44 | }); |
| 45 | |
| 46 | okscip-perl cpan Catmandu-XSD 0.05 main/ok(). $exporter->commitscip-perl cpan Catmandu-XSD 0.05 Catmandu/commit().; |
| 47 | |
| 48 | likescip-perl cpan Catmandu-XSD 0.05 main/like(). $xml , qr/<\?xml version="1.0" encoding="UTF-8"\?>/ , 'looks like XML'; |
| 49 | |
| 50 | my $doc = XML::LibXML->load_xmlscip-perl cpan Catmandu-XSD 0.05 XML/LibXML/load_xml().(string => $xml); |
| 51 | |
| 52 | okscip-perl cpan Catmandu-XSD 0.05 main/ok(). $doc , 'is XML'; |
| 53 | |
| 54 | my $xc = XML::LibXML::XPathContext->newscip-perl cpan Catmandu-XSD 0.05 XML/LibXML/XPathContext/new().($doc); |
| 55 | |
| 56 | isscip-perl cpan Catmandu-XSD 0.05 main/is(). $xc->findvaluescip-perl cpan Catmandu-XSD 0.05 XML/LibXML/XPathContext/findvalue().('/shiporder/item/title') , 'Empire Burlesque' , '/shiporder/item/title'; |
| 57 | } |
| 58 | |
| 59 | { |
| 60 | my $xml = ''; |
| 61 | |
| 62 | my $exporter = Catmandu->exporterscip-perl cpan Catmandu-XSD 0.05 Catmandu/exporter().('XSD' , |
| 63 | file => \$xml , |
| 64 | root => '{}shiporder' , |
| 65 | schemas => 't/demo/order/*.xsd' , |
| 66 | template_before => 'demo/order/xml_header.tt' , |
| 67 | template => 'demo/order/xml_record.tt' , |
| 68 | template_after => 'demo/order/xml_footer.tt' , |
| 69 | ); |
| 70 | |
| 71 | okscip-perl cpan Catmandu-XSD 0.05 main/ok(). $exporter , 'got an exporter' ; |
| 72 | |
| 73 | okscip-perl cpan Catmandu-XSD 0.05 main/ok(). $exporter->addscip-perl cpan Catmandu-XSD 0.05 Catmandu/add().({ |
| 74 | orderid => 889924 , |
| 75 | orderperson => 'Olga Brown' , |
| 76 | shipto => { |
| 77 | name => 'Kalevia Aho' , |
| 78 | address => 'Monstreet 3' , |
| 79 | city => '9000 Emarald' , |
| 80 | country => 'Canada' , |
| 81 | date => '2014-11-03' |
| 82 | } , |
| 83 | item => { |
| 84 | title => 'Empire Burlesque' , |
| 85 | note => 'Special Edition' , |
| 86 | quantity => 1 , |
| 87 | price => 10.90 |
| 88 | } |
| 89 | }); |
| 90 | |
| 91 | okscip-perl cpan Catmandu-XSD 0.05 main/ok(). $exporter->commitscip-perl cpan Catmandu-XSD 0.05 Catmandu/commit().; |
| 92 | |
| 93 | likescip-perl cpan Catmandu-XSD 0.05 main/like(). $xml , qr/<\?xml version="1.0" encoding="UTF-8"\?>/ , 'looks like XML'; |
| 94 | |
| 95 | my $doc = XML::LibXML->load_xmlscip-perl cpan Catmandu-XSD 0.05 XML/LibXML/load_xml().(string => $xml); |
| 96 | |
| 97 | okscip-perl cpan Catmandu-XSD 0.05 main/ok(). $doc , 'is XML'; |
| 98 | |
| 99 | my $xc = XML::LibXML::XPathContext->newscip-perl cpan Catmandu-XSD 0.05 XML/LibXML/XPathContext/new().($doc); |
| 100 | |
| 101 | isscip-perl cpan Catmandu-XSD 0.05 main/is(). $xc->findvaluescip-perl cpan Catmandu-XSD 0.05 XML/LibXML/XPathContext/findvalue().('/Container/List/Record/Payload/shiporder/item/title') , 'Empire Burlesque' , '/shiporder/item/title'; |
| 102 | } |
| 103 | |
| 104 | { |
| 105 | my $xml = ''; |
| 106 | |
| 107 | my $exporter = Catmandu->exporterscip-perl cpan Catmandu-XSD 0.05 Catmandu/exporter().('XSD' , |
| 108 | file => \$xml , |
| 109 | root => '{}shiporder' , |
| 110 | schemas => 't/demo/order/*.xsd' , |
| 111 | split => 1 , |
| 112 | split_directory => 't' , |
| 113 | split_pattern => 'id_%s.xml' , |
| 114 | ); |
| 115 | |
| 116 | okscip-perl cpan Catmandu-XSD 0.05 main/ok(). $exporter , 'got an exporter' ; |
| 117 | |
| 118 | okscip-perl cpan Catmandu-XSD 0.05 main/ok(). $exporter->addscip-perl cpan Catmandu-XSD 0.05 Catmandu/add().({ |
| 119 | orderid => 889924 , |
| 120 | orderperson => 'Olga Brown' , |
| 121 | shipto => { |
| 122 | name => 'Kalevia Aho' , |
| 123 | address => 'Monstreet 3' , |
| 124 | city => '9000 Emarald' , |
| 125 | country => 'Canada' , |
| 126 | date => '2014-11-03' |
| 127 | } , |
| 128 | item => { |
| 129 | title => 'Empire Burlesque' , |
| 130 | note => 'Special Edition' , |
| 131 | quantity => 1 , |
| 132 | price => 10.90 |
| 133 | } |
| 134 | }); |
| 135 | |
| 136 | okscip-perl cpan Catmandu-XSD 0.05 main/ok(). $exporter->commitscip-perl cpan Catmandu-XSD 0.05 Catmandu/commit().; |
| 137 | |
| 138 | ok -rscip-perl cpan Catmandu-XSD 0.05 main/r(). 't/id_0.xml' , 'found a new file'; |
| 139 | } |
| 140 | |
| 141 | unlinkscip-perl cpan Catmandu-XSD 0.05 main/unlink(). 't/id_0.xml'; |
| 142 | |
| 143 | done_testing 18; |