1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498
|
use strict;
use warnings;
use Test::More;
use IO::File;
use File::Spec;
use XML::Simple;
# Initialise filenames and check they're there
my $XMLFile = File::Spec->catfile('t', 'test1.xml'); # t/test1.xml
unless(-e $XMLFile) {
plan skip_all => 'Test data missing';
}
plan tests => 132;
my $last_warning = '';
is($@, '', 'Module compiled OK');
my $version = 'unknown';
if(open my $chg, '<Changes') {
while(<$chg>) {
last if ($version) = $_ =~ /^([\d\._]+) /;
}
close($chg);
}
unless($XML::Simple::VERSION eq $version) {
diag("Warning: XML::Simple::VERSION = $XML::Simple::VERSION (Changes version: $version)");
}
# Start by parsing an extremely simple piece of XML
my $opt = XMLin(q(<opt name1="value1" name2="value2"></opt>));
my $expected = {
name1 => 'value1',
name2 => 'value2',
};
ok(1, "XMLin() didn't crash");
ok(defined($opt), 'and it returned a value');
is(ref($opt), 'HASH', 'and a hasref at that');
is_deeply($opt, $expected, 'matches expectations (attributes)');
# Now try a slightly more complex one that returns the same value
$opt = XMLin(q(
<opt>
<name1>value1</name1>
<name2>value2</name2>
</opt>
));
is_deeply($opt, $expected, 'same again with nested elements');
# And something else that returns the same (line break included to pick up
# missing /s bug)
$opt = XMLin(q(<opt name1="value1"
name2="value2" />));
is_deeply($opt, $expected, 'attributes in empty element');
# Try something with two lists of nested values
$opt = XMLin(q(
<opt>
<name1>value1.1</name1>
<name1>value1.2</name1>
<name1>value1.3</name1>
<name2>value2.1</name2>
<name2>value2.2</name2>
<name2>value2.3</name2>
</opt>)
);
is_deeply($opt, {
name1 => [ 'value1.1', 'value1.2', 'value1.3' ],
name2 => [ 'value2.1', 'value2.2', 'value2.3' ],
}, 'repeated child elements give arrays of scalars');
# Now a simple nested hash
$opt = XMLin(q(
<opt>
<item name1="value1" name2="value2" />
</opt>)
);
is_deeply($opt, {
item => { name1 => 'value1', name2 => 'value2' }
}, 'nested element gives hash');
# Now a list of nested hashes
$opt = XMLin(q(
<opt>
<item name1="value1" name2="value2" />
<item name1="value3" name2="value4" />
</opt>)
);
is_deeply($opt, {
item => [
{ name1 => 'value1', name2 => 'value2' },
{ name1 => 'value3', name2 => 'value4' }
]
}, 'repeated child elements give list of hashes');
# Now a list of nested hashes transformed into a hash using default key names
my $string = q(
<opt>
<item name="item1" attr1="value1" attr2="value2" />
<item name="item2" attr1="value3" attr2="value4" />
</opt>
);
my $target = {
item => {
item1 => { attr1 => 'value1', attr2 => 'value2' },
item2 => { attr1 => 'value3', attr2 => 'value4' }
}
};
$opt = XMLin($string);
is_deeply($opt, $target, "array folded on default key 'name'");
# Same thing left as an array by suppressing default key names
$target = {
item => [
{name => 'item1', attr1 => 'value1', attr2 => 'value2' },
{name => 'item2', attr1 => 'value3', attr2 => 'value4' }
]
};
my @cont_key = (contentkey => '-content');
$opt = XMLin($string, keyattr => [], @cont_key);
is_deeply($opt, $target, 'not folded when keyattr turned off');
# Same again with alternative key suppression
$opt = XMLin($string, keyattr => {}, @cont_key);
is_deeply($opt, $target, 'still works when keyattr is empty hash');
# Try the other two default key attribute names
$opt = XMLin(q(
<opt>
<item key="item1" attr1="value1" attr2="value2" />
<item key="item2" attr1="value3" attr2="value4" />
</opt>
), @cont_key);
is_deeply($opt, {
item => {
item1 => { attr1 => 'value1', attr2 => 'value2' },
item2 => { attr1 => 'value3', attr2 => 'value4' }
}
}, "folded on default key 'key'");
$opt = XMLin(q(
<opt>
<item id="item1" attr1="value1" attr2="value2" />
<item id="item2" attr1="value3" attr2="value4" />
</opt>
), @cont_key);
is_deeply($opt, {
item => {
item1 => { attr1 => 'value1', attr2 => 'value2' },
item2 => { attr1 => 'value3', attr2 => 'value4' }
}
}, "folded on default key 'id'");
# Similar thing using non-standard key names
my $xml = q(
<opt>
<item xname="item1" attr1="value1" attr2="value2" />
<item xname="item2" attr1="value3" attr2="value4" />
</opt>);
$target = {
item => {
item1 => { attr1 => 'value1', attr2 => 'value2' },
item2 => { attr1 => 'value3', attr2 => 'value4' }
}
};
$opt = XMLin($xml, keyattr => [qw(xname)], @cont_key);
is_deeply($opt, $target, "folded on non-default key 'xname'");
# And with precise element/key specification
$opt = XMLin($xml, keyattr => { 'item' => 'xname' }, @cont_key);
is_deeply($opt, $target, 'same again but keyattr set with hash');
# Same again but with key field further down the list
$opt = XMLin($xml, keyattr => [qw(wibble xname)], @cont_key);
is_deeply($opt, $target, 'keyattr as array with value in second position');
# Same again but with key field supplied as scalar
$opt = XMLin($xml, keyattr => qw(xname), @cont_key);
is_deeply($opt, $target, 'keyattr as scalar');
# Same again but with mixed-case option name
$opt = XMLin($xml, KeyAttr => qw(xname), @cont_key);
is_deeply($opt, $target, 'KeyAttr as scalar');
# Same again but with underscores in option name
$opt = XMLin($xml, key_attr => qw(xname), @cont_key);
is_deeply($opt, $target, 'key_attr as scalar');
# Weird variation, not exactly what we wanted but it is what we expected
# given the current implementation and we don't want to break it accidently
$xml = q(
<opt>
<item id="one" value="1" name="a" />
<item id="two" value="2" />
<item id="three" value="3" />
</opt>
);
$target = { item => {
'three' => { 'value' => 3 },
'a' => { 'value' => 1, 'id' => 'one' },
'two' => { 'value' => 2 }
}
};
$opt = XMLin($xml, @cont_key);
is_deeply($opt, $target, 'fold same array on two different keys');
# Or somewhat more as one might expect
$target = { item => {
'one' => { 'value' => '1', 'name' => 'a' },
'two' => { 'value' => '2' },
'three' => { 'value' => '3' },
}
};
$opt = XMLin($xml, keyattr => { 'item' => 'id' }, @cont_key);
is_deeply($opt, $target, 'same again but with priority switch');
# Now a somewhat more complex test of targetting folding
$xml = q(
<opt>
<car license="SH6673" make="Ford" id="1">
<option key="1" pn="6389733317-12" desc="Electric Windows"/>
<option key="2" pn="3735498158-01" desc="Leather Seats"/>
<option key="3" pn="5776155953-25" desc="Sun Roof"/>
</car>
<car license="LW1804" make="GM" id="2">
<option key="1" pn="9926543-1167" desc="Steering Wheel"/>
</car>
</opt>
);
$target = {
'car' => {
'LW1804' => {
'id' => 2,
'make' => 'GM',
'option' => {
'9926543-1167' => { 'key' => 1, 'desc' => 'Steering Wheel' }
}
},
'SH6673' => {
'id' => 1,
'make' => 'Ford',
'option' => {
'6389733317-12' => { 'key' => 1, 'desc' => 'Electric Windows' },
'3735498158-01' => { 'key' => 2, 'desc' => 'Leather Seats' },
'5776155953-25' => { 'key' => 3, 'desc' => 'Sun Roof' }
}
}
}
};
$opt = XMLin($xml, forcearray => 1,
keyattr => { 'car' => 'license', 'option' => 'pn' }, @cont_key);
is_deeply($opt, $target, 'folded on multi-key keyattr hash');
# Now try leaving the keys in place
$target = {
'car' => {
'LW1804' => {
'id' => 2,
'make' => 'GM',
'option' => {
'9926543-1167' => { 'key' => 1, 'desc' => 'Steering Wheel',
'-pn' => '9926543-1167' }
},
license => 'LW1804'
},
'SH6673' => {
'id' => 1,
'make' => 'Ford',
'option' => {
'6389733317-12' => { 'key' => 1, 'desc' => 'Electric Windows',
'-pn' => '6389733317-12' },
'3735498158-01' => { 'key' => 2, 'desc' => 'Leather Seats',
'-pn' => '3735498158-01' },
'5776155953-25' => { 'key' => 3, 'desc' => 'Sun Roof',
'-pn' => '5776155953-25' }
},
license => 'SH6673'
}
}
};
$opt = XMLin($xml, forcearray => 1, keyattr => { 'car' => '+license', 'option' => '-pn' }, @cont_key);
is_deeply($opt, $target, "same again but with '+' prefix to copy keys");
# Confirm the stringifying references bug is fixed
$xml = q(
<opt>
<item>
<name><firstname>Bob</firstname></name>
<age>21</age>
</item>
<item>
<name><firstname>Kate</firstname></name>
<age>22</age>
</item>
</opt>);
$target = {
item => [
{ age => '21', name => { firstname => 'Bob'} },
{ age => '22', name => { firstname => 'Kate'} },
]
};
{
local($SIG{__WARN__}) = \&warn_handler;
$last_warning = '';
$opt = XMLin($xml, @cont_key);
is_deeply($opt, $target, "did not fold on default key with non-scalar value");
is($last_warning, '', 'no warning issued');
$last_warning = '';
$opt = XMLin($xml, keyattr => { item => 'name' }, @cont_key);
is_deeply($opt, $target, "did not fold on specific key with non-scalar value");
isnt($last_warning, '', 'warning issued as expected');
like($last_warning,
qr{<item> element has non-scalar 'name' key attribute},
'text in warning is correct'
);
$last_warning = '';
$opt = XMLin($xml, keyattr => [ 'name' ], @cont_key);
is_deeply($opt, $target, "same again but with keyattr as array");
isnt($last_warning, '', 'warning issued as expected');
like($last_warning,
qr{<item> element has non-scalar 'name' key attribute},
'text in warning is correct'
);
$last_warning = '';
{
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 = '';
my $xitems = q(<opt>
<item name="color">red</item>
<item name="mass">heavy</item>
<item nime="disposition">ornery</item>
</opt>);
my $items = {
'item' => [
{ 'name' => 'color', 'content' => 'red', },
{ 'name' => 'mass', 'content' => 'heavy', },
{ 'nime' => 'disposition', 'content' => 'ornery', }
]
};
$opt = XMLin($xitems, keyattr => { item => 'name' }, @cont_key);
is_deeply($opt, $items, "did not fold when element missing key attribute");
like($last_warning, qr{Warning: <item> element has no 'name' key attribute},
'expected warning issued');
$last_warning = '';
{
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 = '';
$xitems = q(<opt>
<item name="color">red</item>
<item name="mass">heavy</item>
<item name="disposition">ornery</item>
<item name="color">green</item>
</opt>);
$items = {
'item' => {
'color' => 'green',
'mass' => 'heavy',
'disposition' => 'ornery',
}
};
$opt = XMLin($xitems, keyattr => { item => 'name' }, @cont_key);
is_deeply($opt, $items, "folded elements despite non-unique key attribute");
like($last_warning, qr{Warning: <item> element has non-unique value in 'name' key attribute: color},
'expected warning issued');
$last_warning = '';
$opt = XMLin($xitems, keyattr => [ 'name' ], @cont_key);
is_deeply($opt, $items, "same again but with keyattr as array");
like($last_warning, qr{Warning: <item> element has non-unique value in 'name' key attribute: color},
'expected warning issued');
$last_warning = '';
{
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');
}
}
# Make sure that the root element name is preserved if we ask for it
$target = XMLin("<opt>$xml</opt>", forcearray => 1,
keyattr => { 'car' => '+license', 'option' => '-pn' },
@cont_key);
$opt = XMLin( $xml, forcearray => 1, keeproot => 1,
keyattr => { 'car' => '+license', 'option' => '-pn' },
@cont_key);
is_deeply($opt, $target, 'keeproot option works');
# confirm that CDATA sections parse correctly
$xml = q{<opt><cdata><![CDATA[<greeting>Hello, world!</greeting>]]></cdata></opt>};
$opt = XMLin($xml, @cont_key);
is_deeply($opt, {
'cdata' => '<greeting>Hello, world!</greeting>'
}, 'CDATA section parsed correctly');
$xml = q{<opt><x><![CDATA[<y>one</y>]]><![CDATA[<y>two</y>]]></x></opt>};
$opt = XMLin($xml, @cont_key);
is_deeply($opt, {
'x' => '<y>one</y><y>two</y>'
}, 'CDATA section containing markup characters parsed correctly');
# Try parsing a named external file
$opt = eval{ XMLin($XMLFile); };
is($@, '', "XMLin didn't choke on named external file");
is_deeply($opt, {
location => 't/test1.xml'
}, 'and contents parsed as expected');
# 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, {
location => 't/1_XMLin.xml'
}, 'and contents parsed as expected');
# 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
] );
};
is($@, '', 'XMLin found file using searchpath');
is_deeply($opt, {
location => 't/subdir/test2.xml'
}, 'and contents parsed as expected');
# Ensure we get expected result if file does not exist
$opt = undef;
$opt = eval {
XMLin('bogusfile.xml', searchpath => 't' ); # should 'die'
};
is($opt, undef, 'XMLin choked on nonexistant file');
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');
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 {
$fh->open($XMLFile) || die "$!";
$opt = XMLin($fh, @cont_key);
};
is($@, '', "XMLin didn't choke on an IO::File object");
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('-');
};
is($@, '', "XMLin didn't choke on STDIN ('-')");
is($opt->{location}, 't/1_XMLin.xml', 'and data parsed correctly');
# Confirm anonymous array handling works in general
$xml = q{
<opt>
<row>
<anon>0.0</anon><anon>0.1</anon><anon>0.2</anon>
</row>
<row>
<anon>1.0</anon><anon>1.1</anon><anon>1.2</anon>
</row>
<row>
<anon>2.0</anon><anon>2.1</anon><anon>2.2</anon>
</row>
</opt>
};
$expected = {
row => [
[ '0.0', '0.1', '0.2' ],
[ '1.0', '1.1', '1.2' ],
[ '2.0', '2.1', '2.2' ]
]
};
$opt = XMLin($xml, @cont_key);
is_deeply($opt, $expected, 'anonymous arrays parsed correctly');
# Confirm it still works with array folding disabled (was a bug)
$opt = XMLin($xml, keyattr => [], @cont_key);
is_deeply($opt, $expected, 'anonymous arrays parsed correctly');
# Confirm anonymous array handling works in special top level case
$opt = XMLin(q{
<opt>
<anon>one</anon>
<anon>two</anon>
<anon>three</anon>
</opt>
}, @cont_key);
is_deeply($opt, [
qw(one two three)
], 'top level anonymous array returned arrayref');
$opt = XMLin(q(
<opt>
<anon>1</anon>
<anon>
<anon>2.1</anon>
<anon>
<anon>2.2.1</anon>
<anon>2.2.2</anon>
</anon>
</anon>
</opt>
), @cont_key);
is_deeply($opt, [
1,
[
'2.1', [ '2.2.1', '2.2.2']
]
], 'nested anonymous arrays parsed correctly');
# Check for the dreaded 'content' attribute
$xml = q(
<opt>
<item attr="value">text</item>
</opt>
);
$opt = XMLin($xml);
is_deeply($opt, {
item => {
content => 'text',
attr => 'value'
}
}, "'content' key appears as expected");
# And check that we can change its name if required
$opt = XMLin($xml, contentkey => 'text_content');
is_deeply($opt, {
item => {
text_content => 'text',
attr => 'value'
}
}, "'content' key successfully renamed to 'text'");
# Check that it doesn't get screwed up by forcearray option
$xml = q(<opt attr="value">text content</opt>);
$opt = XMLin($xml, forcearray => 1);
is_deeply($opt, {
'attr' => 'value',
'content' => 'text content'
}, "'content' key not munged by forcearray");
# Test that we can force all text content to parse to hash values
$xml = q(<opt><x>text1</x><y a="2">text2</y></opt>);
$opt = XMLin($xml, forcecontent => 1);
is_deeply($opt, {
'x' => { 'content' => 'text1' },
'y' => { 'a' => 2, 'content' => 'text2' }
}, 'gratuitous use of content key works as expected');
# And that this is compatible with changing the key name
$opt = XMLin($xml, forcecontent => 1, contentkey => '0');
is_deeply($opt, {
'x' => { 0 => 'text1' },
'y' => { 'a' => 2, 0 => 'text2' }
}, "even when we change it's name to 'text'");
# Confirm that spurious 'content' keys are *not* eliminated after array folding
$xml = q(<opt><x y="one">First</x><x y="two">Second</x></opt>);
$opt = XMLin($xml, forcearray => [ 'x' ], keyattr => {x => 'y'});
is_deeply($opt, {
x => {
one => { content => 'First' },
two => { content => 'Second' },
}
}, "spurious content keys not eliminated after folding");
# unless we ask nicely
$xml = q(<opt><x y="one">First</x><x y="two">Second</x></opt>);
$opt = XMLin(
$xml, forcearray => [ 'x' ], keyattr => {x => 'y'}, contentkey => '-content'
);
is_deeply($opt, {
x => {
one => 'First',
two => 'Second',
}
}, "spurious content keys not eliminated after folding");
# Check that mixed content parses in the weird way we expect
$xml = q(<opt>
<p1 class="mixed">Text with a <b>bold</b> word</p1>
<p2>Mixed <b>but</b> no attributes</p2>
</opt>);
is_deeply(XMLin($xml, @cont_key), {
'p1' => {
'content' => [ 'Text with a ', ' word' ],
'class' => 'mixed',
'b' => 'bold'
},
'p2' => {
'content' => [ 'Mixed ', ' no attributes' ],
'b' => 'but'
}
}, "mixed content doesn't work - no surprises there");
# Confirm single nested element rolls up into a scalar attribute value
$string = q(
<opt>
<name>value</name>
</opt>
);
$opt = XMLin($string);
is_deeply($opt, {
name => 'value'
}, 'nested element rolls up to scalar');
# Unless 'forcearray' option is specified
$opt = XMLin($string, forcearray => 1, @cont_key);
is_deeply($opt, {
name => [ 'value' ]
}, 'except when forcearray is enabled');
# Confirm array folding of single nested hash
$string = q(<opt>
<inner name="one" value="1" />
</opt>);
$opt = XMLin($string, forcearray => 1, @cont_key);
is_deeply($opt, {
'inner' => { 'one' => { 'value' => 1 } }
}, 'array folding works with single nested hash');
# But not without forcearray option specified
$opt = XMLin($string, forcearray => 0, @cont_key);
is_deeply($opt, {
'inner' => { 'name' => 'one', 'value' => 1 }
}, 'but not if forcearray is turned off');
# Test advanced features of forcearray
$xml = q(<opt zero="0">
<one>i</one>
<two>ii</two>
<three>iii</three>
<three>3</three>
<three>c</three>
</opt>
);
$opt = XMLin($xml, forcearray => [ 'two' ], @cont_key);
is_deeply($opt, {
'zero' => '0',
'one' => 'i',
'two' => [ 'ii' ],
'three' => [ 'iii', 3, 'c' ]
}, 'selective application of forcearray successful');
# Test forcearray regexes
$xml = q(<opt zero="0">
<one>i</one>
<two>ii</two>
<three>iii</three>
<four>iv</four>
<five>v</five>
</opt>
);
$opt = XMLin($xml, forcearray => [ qr/^f/, 'two', qr/n/ ], @cont_key);
is_deeply($opt, {
'zero' => '0',
'one' => [ 'i' ],
'two' => [ 'ii' ],
'three' => 'iii',
'four' => [ 'iv' ],
'five' => [ 'v' ],
}, 'forcearray using regex successful');
# Same again but a single regexp rather than in an arrayref
$opt = XMLin($xml, forcearray => qr/^f|e$/, @cont_key);
is_deeply($opt, {
'zero' => '0',
'one' => [ 'i' ],
'two' => 'ii',
'three' => [ 'iii'],
'four' => [ 'iv' ],
'five' => [ 'v' ],
}, 'forcearray using a single regex successful');
# Test 'noattr' option
$xml = q(<opt name="user" password="foobar">
<nest attr="value">text</nest>
</opt>
);
$opt = XMLin($xml, noattr => 1, @cont_key);
is_deeply($opt, { nest => 'text' }, 'attributes successfully skipped');
# And make sure it doesn't screw up array folding
$xml = q{<opt>
<item><key>a</key><value>alpha</value></item>
<item><key>b</key><value>beta</value></item>
<item><key>g</key><value>gamma</value></item>
</opt>
};
$opt = XMLin($xml, noattr => 1, @cont_key);
is_deeply($opt, {
'item' => {
'a' => { 'value' => 'alpha' },
'b' => { 'value' => 'beta' },
'g' => { 'value' => 'gamma' }
}
}, 'noattr does not intefere with array folding');
# Confirm empty elements parse to empty hashrefs
$xml = q(<body>
<name>bob</name>
<outer attr="value">
<inner1 />
<inner2></inner2>
</outer>
</body>);
$opt = XMLin($xml, noattr => 1, @cont_key);
is_deeply($opt, {
'name' => 'bob',
'outer' => {
'inner1' => {},
'inner2' => {}
}
}, 'empty elements parse to hashrefs');
# Unless 'suppressempty' is enabled
$opt = XMLin($xml, noattr => 1, suppressempty => 1, @cont_key);
is_deeply($opt, { 'name' => 'bob', }, 'or are suppressed');
# Check behaviour when 'suppressempty' is set to to undef;
$opt = XMLin($xml, noattr => 1, suppressempty => undef, @cont_key);
is_deeply($opt, {
'name' => 'bob',
'outer' => {
'inner1' => undef,
'inner2' => undef
}
}, "or parse to 'undef'");
# Check behaviour when 'suppressempty' is set to to empty string;
$opt = XMLin($xml, noattr => 1, suppressempty => '', @cont_key);
is_deeply($opt, {
'name' => 'bob',
'outer' => {
'inner1' => '',
'inner2' => ''
}
}, 'or parse to an empty string');
# Confirm completely empty XML parses to undef with 'suppressempty'
$xml = q(<body>
<outer attr="value">
<inner1 />
<inner2></inner2>
</outer>
</body>);
$opt = XMLin($xml, noattr => 1, suppressempty => 1, @cont_key);
is($opt, undef, 'empty document parses to undef');
# Confirm nothing magical happens with grouped elements
$xml = q(<opt>
<prefix>before</prefix>
<dirs>
<dir>/usr/bin</dir>
<dir>/usr/local/bin</dir>
</dirs>
<suffix>after</suffix>
</opt>);
$opt = XMLin($xml);
is_deeply($opt, {
prefix => 'before',
dirs => {
dir => [ '/usr/bin', '/usr/local/bin' ]
},
suffix => 'after',
}, 'grouped tags parse normally');
# unless we specify how the grouping works
$xml = q(<opt>
<prefix>before</prefix>
<dirs>
<dir>/usr/bin</dir>
<dir>/usr/local/bin</dir>
</dirs>
<suffix>after</suffix>
</opt>);
$opt = XMLin($xml, grouptags => {dirs => 'dir'} );
is_deeply($opt, {
prefix => 'before',
dirs => [ '/usr/bin', '/usr/local/bin' ],
suffix => 'after',
}, 'disintermediation of grouped tags works');
# try again with multiple groupings
$xml = q(<opt>
<prefix>before</prefix>
<dirs>
<dir>/usr/bin</dir>
<dir>/usr/local/bin</dir>
</dirs>
<infix>between</infix>
<terms>
<term>vt100</term>
<term>xterm</term>
</terms>
<suffix>after</suffix>
</opt>);
$opt = XMLin($xml, grouptags => {dirs => 'dir', terms => 'term'} );
is_deeply($opt, {
prefix => 'before',
dirs => [ '/usr/bin', '/usr/local/bin' ],
infix => 'between',
terms => [ 'vt100', 'xterm' ],
suffix => 'after',
}, 'disintermediation works with multiple groups');
# confirm folding and ungrouping work together
$xml = q(<opt>
<prefix>before</prefix>
<dirs>
<dir name="first">/usr/bin</dir>
<dir name="second">/usr/local/bin</dir>
</dirs>
<suffix>after</suffix>
</opt>);
$opt = XMLin($xml, keyattr => {dir => 'name'}, grouptags => {dirs => 'dir'} );
is_deeply($opt, {
prefix => 'before',
dirs => {
first => { content => '/usr/bin' },
second => { content => '/usr/local/bin' },
},
suffix => 'after',
}, 'folding and ungrouping work together');
# confirm folding, ungrouping and content stripping work together
$xml = q(<opt>
<prefix>before</prefix>
<dirs>
<dir name="first">/usr/bin</dir>
<dir name="second">/usr/local/bin</dir>
</dirs>
<suffix>after</suffix>
</opt>);
$opt = XMLin($xml,
contentkey => '-text',
keyattr => {dir => 'name'},
grouptags => {dirs => 'dir'}
);
is_deeply($opt, {
prefix => 'before',
dirs => {
first => '/usr/bin',
second => '/usr/local/bin',
},
suffix => 'after',
}, 'folding, ungrouping and content stripping work together');
# confirm folding fails as expected even with ungrouping but (no forcearray)
$xml = q(<opt>
<prefix>before</prefix>
<dirs>
<dir name="first">/usr/bin</dir>
</dirs>
<suffix>after</suffix>
</opt>);
$opt = XMLin($xml,
contentkey => '-text',
keyattr => {dir => 'name'},
grouptags => {dirs => 'dir'}
);
is_deeply($opt, {
prefix => 'before',
dirs => { name => 'first', text => '/usr/bin'},
suffix => 'after',
}, 'folding without forcearray but with ungrouping fails as expected');
# but works with forcearray enabled
$xml = q(<opt>
<prefix>before</prefix>
<dirs>
<dir name="first">/usr/bin</dir>
</dirs>
<suffix>after</suffix>
</opt>);
$opt = XMLin($xml,
contentkey => '-text',
forcearray => [ 'dir' ],
keyattr => {dir => 'name'},
grouptags => {dirs => 'dir'}
);
is_deeply($opt, {
prefix => 'before',
dirs => {'first' => '/usr/bin'},
suffix => 'after',
}, 'folding with forcearray and ungrouping works');
# Test variable expansion - when no variables are defined
$xml = q(<opt>
<file name="config_file">${conf_dir}/appname.conf</file>
<file name="log_file">${log_dir}/appname.log</file>
<file name="debug_file">${log_dir}/appname.dbg</file>
<opt docs="${have_docs}" />
<bogus value="${undef}" />
</opt>);
$opt = XMLin($xml, contentkey => '-content');
is_deeply($opt, {
file => {
config_file => '${conf_dir}/appname.conf',
log_file => '${log_dir}/appname.log',
debug_file => '${log_dir}/appname.dbg',
},
opt => { docs => '${have_docs}' },
bogus => { value => '${undef}' }
}, 'undefined variables are left untouched');
# try again but with variables defined in advance
$opt = XMLin($xml,
contentkey => '-content',
variables => { conf_dir => '/etc', log_dir => '/var/log',
have_docs => 'true' }
);
is_deeply($opt, {
file => {
config_file => '/etc/appname.conf',
log_file => '/var/log/appname.log',
debug_file => '/var/log/appname.dbg',
},
opt => { docs => 'true' },
bogus => { value => '${undef}' }
}, 'substitution of pre-defined variables works');
# now try defining them in the XML
$xml = q(<opt>
<dir xsvar="conf_dir">/etc</dir>
<dir xsvar="log_dir">/var/log</dir>
<cfg xsvar="have_docs">false</cfg>
<cfg xsvar="host.domain">search.perl.org</cfg>
<cfg xsvar="bad/name">bogus</cfg>
<file name="config_file">${conf_dir}/appname.conf</file>
<file name="log_file">${log_dir}/appname.log</file>
<file name="debug_file">${log_dir}/appname.dbg</file>
<file name="bogus_file">${bad/name}</file>
<opt docs="${have_docs}" />
<site url="http://${host.domain}/" />
</opt>);
$opt = XMLin($xml, contentkey => '-content', varattr => 'xsvar');
is_deeply($opt, {
file => {
config_file => '/etc/appname.conf',
log_file => '/var/log/appname.log',
debug_file => '/var/log/appname.dbg',
bogus_file => '${bad/name}', # '/' is not valid in a var name
},
opt => { docs => 'false' },
site => { url => 'http://search.perl.org/' },
dir => [
{ xsvar => 'conf_dir', content => '/etc' },
{ xsvar => 'log_dir', content => '/var/log' },
],
cfg => [
{ xsvar => 'have_docs', content => 'false' },
{ xsvar => 'host.domain', content => 'search.perl.org' },
{ xsvar => 'bad/name', content => 'bogus' },
],
}, 'variables defined in XML work');
# confirm that variables in XML are merged with pre-defined ones
$xml = q(<opt>
<dir xsvar="log_dir">/var/log</dir>
<file name="config_file">${conf_dir}/appname.conf</file>
<file name="log_file">${log_dir}/appname.log</file>
<file name="debug_file">${log_dir}/appname.dbg</file>
</opt>);
$opt = XMLin($xml,
contentkey => '-content',
varattr => 'xsvar',
variables => { conf_dir => '/etc', log_dir => '/tmp' }
);
is_deeply($opt, {
file => {
config_file => '/etc/appname.conf',
log_file => '/var/log/appname.log',
debug_file => '/var/log/appname.dbg',
},
dir => { xsvar => 'log_dir', content => '/var/log' },
}, 'variables defined in XML merged successfully with predefined vars');
# confirm that a variables are expanded in variable definitions
$xml = q(<opt>
<dirs>
<dir name="prefix">/usr/local/apache</dir>
<dir name="exec_prefix">${prefix}</dir>
<dir name="bin_dir">${exec_prefix}/bin</dir>
</dirs>
</opt>);
$opt = XMLin($xml,
contentkey => '-content',
varattr => 'name',
grouptags => { dirs => 'dir' },
);
is_deeply($opt, {
dirs => {
prefix => '/usr/local/apache',
exec_prefix => '/usr/local/apache',
bin_dir => '/usr/local/apache/bin',
}
}, 'variables are expanded in later variable definitions');
# 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/,
'with correct error message');
# Try to disintermediate on the wrong child key
$xml = q(<opt>
<prefix>before</prefix>
<dirs>
<lib>/usr/bin</lib>
<lib>/usr/local/bin</lib>
</dirs>
<suffix>after</suffix>
</opt>);
$opt = XMLin($xml, grouptags => {dirs => 'dir'} );
is_deeply($opt, {
prefix => 'before',
dirs => { lib => [ '/usr/bin', '/usr/local/bin' ] },
suffix => 'after',
}, 'disintermediation using wrong child key - as expected');
# Test option error handling
$_ = eval { XMLin('<x y="z" />', rootname => 'fred') }; # not valid for XMLin()
is($_, undef, 'invalid options are trapped');
like($@, qr/Unrecognised option:/, 'with correct error message');
$_ = eval { XMLin('<x y="z" />', 'searchpath') };
is($_, undef, 'invalid number of options are trapped');
like($@, qr/Options must be name=>value pairs \(odd number supplied\)/,
'with correct error message');
# Test the NormaliseSpace option
$xml = q(<opt>
<user name=" Joe
Bloggs " id=" one two "/>
<user>
<name> Jane
Doe </name>
<id>
three
four
</id>
</user>
</opt>);
$opt = XMLin($xml, KeyAttr => [ 'name' ], NormaliseSpace => 1);
ok(ref($opt->{user}) eq 'HASH', "NS-1: folding OK");
ok(exists($opt->{user}->{'Joe Bloggs'}), "NS-2: space normalised in hash key");
ok(exists($opt->{user}->{'Jane Doe'}), "NS-3: space normalised in hash key");
like($opt->{user}->{'Jane Doe'}->{id}, qr{^\s\s+three\s\s+four\s\s+$}s,
"NS-4: space not normalised in hash value");
$opt = XMLin($xml, KeyAttr => { user => 'name' }, NormaliseSpace => 1);
ok(ref($opt->{user}) eq 'HASH', "NS-1a: folding OK");
ok(exists($opt->{user}->{'Joe Bloggs'}), "NS-2a: space normalised in hash key");
ok(exists($opt->{user}->{'Jane Doe'}), "NS-3a: space normalised in hash key");
like($opt->{user}->{'Jane Doe'}->{id}, qr{^\s\s+three\s\s+four\s\s+$}s,
"NS-4a: space not normalised in hash value");
$opt = XMLin($xml, KeyAttr => [ 'name' ], NormaliseSpace => 2);
ok(ref($opt->{user}) eq 'HASH', "NS-5: folding OK");
ok(exists($opt->{user}->{'Joe Bloggs'}), "NS-6: space normalised in hash key");
like($opt->{user}->{'Joe Bloggs'}->{id}, qr{^one\stwo$}s,
"NS-7: space normalised in attribute value");
ok(exists($opt->{user}->{'Jane Doe'}), "NS-8: space normalised in hash key");
like($opt->{user}->{'Jane Doe'}->{id}, qr{^three\sfour$}s,
"NS-9: space normalised in element text content");
# confirm NormaliseSpace works in anonymous arrays too
$xml = q(<opt>
<anon> one two </anon><anon> three
four five </anon><anon> six </anon><anon> seveneightnine </anon>
</opt>);
$opt = XMLin($xml, NormaliseSpace => 2);
is_deeply($opt, [ 'one two', 'three four five', 'six', 'seveneightnine' ],
"NS-10: space normalised in anonymous array");
# Check that American speeling works too
$opt = XMLin($xml, NormalizeSpace => 2);
is_deeply($opt, [ 'one two', 'three four five', 'six', 'seveneightnine' ],
"NS-11: space normalized in anonymous array");
# Check that attributes called 'value' are not special
$xml = q(<graphics>
<today value="today.png"/>
<nav-prev value="prev.png"/>
<nav-home value="home.png"/>
<nav-next value="next.png"/>
</graphics>);
$opt = XMLin($xml);
is_deeply($opt, {
'today' => { value => "today.png" },
'nav-prev' => { value => "prev.png" },
'nav-home' => { value => "home.png" },
'nav-next' => { value => "next.png" },
}, "Nothing special about 'value' attributes");
# Now turn on the ValueAttr option and try again
$opt = XMLin($xml, ValueAttr => [ 'value' ]);
is_deeply($opt, {
'today' => "today.png",
'nav-prev' => "prev.png",
'nav-home' => "home.png",
'nav-next' => "next.png",
}, "ValueAttr as arrayref works");
# Try with a list of different ValueAttr names
$xml = q(<graphics>
<today xxx="today.png"/>
<nav-prev yyy="prev.png"/>
<nav-home zzz="home.png"/>
<nav-next value="next.png"/>
</graphics>);
$opt = XMLin($xml, ValueAttr => [ qw(xxx yyy zzz) ]);
is_deeply($opt, {
'today' => "today.png",
'nav-prev' => "prev.png",
'nav-home' => "home.png",
'nav-next' => { value => "next.png" },
}, "ValueAttr as arrayref works");
# Try specifying ValueAttr as a hashref
$xml = q(<graphics>
<today xxx="today.png"/>
<nav-prev value="prev.png"/>
<nav-home yyy="home.png"/>
<nav-next value="next.png"/>
</graphics>);
$opt = XMLin($xml,
ValueAttr => {
'today' => 'xxx',
'nav-home' => 'yyy',
'nav-next' => 'value'
}
);
is_deeply($opt, {
'today' => "today.png",
'nav-prev' => { value => "prev.png" },
'nav-home' => "home.png",
'nav-next' => "next.png",
}, "ValueAttr as hashref works too");
# Confirm that there's no conflict with KeyAttr or ContentKey defaults
$xml = q(<graphics>
<today value="today.png"/>
<animal name="lion" age="7"/>
<animal name="elephant" age="97"/>
<colour rgb="#FF0000">red</colour>
</graphics>);
$opt = XMLin($xml, ValueAttr => { 'today' => 'value' });
is_deeply($opt, {
today => 'today.png',
animal => {
lion => { age => 7 },
elephant => { age => 97 },
},
colour => { rgb => '#FF0000', content => 'red' },
}, "ValueAttr as hashref works too");
# Now for a 'real world' test, try slurping in an SRT config file
$opt = XMLin(File::Spec->catfile('t', 'srt.xml'),
forcearray => 1, @cont_key
);
$target = {
'global' => [
{
'proxypswd' => 'bar',
'proxyuser' => 'foo',
'exclude' => [
'/_vt',
'/save\\b',
'\\.bak$',
'\\.\\$\\$\\$$'
],
'httpproxy' => 'http://10.1.1.5:8080/',
'tempdir' => 'C:/Temp'
}
],
'pubpath' => {
'test1' => {
'source' => [
{
'label' => 'web_source',
'root' => 'C:/webshare/web_source'
}
],
'title' => 'web_source -> web_target1',
'package' => {
'images' => { 'dir' => 'wwwroot/images' }
},
'target' => [
{
'label' => 'web_target1',
'root' => 'C:/webshare/web_target1',
'temp' => 'C:/webshare/web_target1/temp'
}
],
'dir' => [ 'wwwroot' ]
},
'test2' => {
'source' => [
{
'label' => 'web_source',
'root' => 'C:/webshare/web_source'
}
],
'title' => 'web_source -> web_target1 & web_target2',
'package' => {
'bios' => { 'dir' => 'wwwroot/staff/bios' },
'images' => { 'dir' => 'wwwroot/images' },
'templates' => { 'dir' => 'wwwroot/templates' }
},
'target' => [
{
'label' => 'web_target1',
'root' => 'C:/webshare/web_target1',
'temp' => 'C:/webshare/web_target1/temp'
},
{
'label' => 'web_target2',
'root' => 'C:/webshare/web_target2',
'temp' => 'C:/webshare/web_target2/temp'
}
],
'dir' => [ 'wwwroot' ]
},
'test3' => {
'source' => [
{
'label' => 'web_source',
'root' => 'C:/webshare/web_source'
}
],
'title' => 'web_source -> web_target1 via HTTP',
'addexclude' => [ '\\.pdf$' ],
'target' => [
{
'label' => 'web_target1',
'root' => 'http://127.0.0.1/cgi-bin/srt_slave.plx',
'noproxy' => 1
}
],
'dir' => [ 'wwwroot' ]
}
}
};
is_deeply($opt, $target, 'successfully read an SRT config file');
exit(0);
sub warn_handler {
$last_warning = $_[0];
}
|