-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyaml2xml
More file actions
executable file
·47 lines (42 loc) · 764 Bytes
/
yaml2xml
File metadata and controls
executable file
·47 lines (42 loc) · 764 Bytes
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
#!/usr/bin/env perl
#
# $Id: yaml2xml,v 1.10 2012/01/13 06:57:15 ryo Exp $
#
# Copyright(c) 2009 Ryo SHIMIZU <ryo@misakimix.org>
#
use strict;
use warnings;
use LWP::Simple;
use XML::Simple;
use YAML::Syck;
if ($#ARGV >= 0) {
for my $file (@ARGV) {
print "== $file ==\n" if ($#ARGV > 0);
yaml2xml(scalar(fileread($file)));
}
} else {
my $file = join("", <>);
yaml2xml($file);
}
exit;
sub yaml2xml {
my $yaml = shift;
my $data = Load($yaml);
print XMLout($data);
}
sub fileread {
my $file = shift;
if ($file =~ m#^(http|https|ftp)://#i) {
my $yaml = get($file);
unless (defined $yaml) {
warn "$file: error\n";
$yaml = '';
}
$yaml;
} else {
open my $fh, "<", $file or die "open: $file: $!\n";
local $/;
undef $/;
<$fh>;
}
}