-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_schemas.pl
executable file
·80 lines (58 loc) · 1.17 KB
/
install_schemas.pl
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
#!/usr/bin/env perl
use File::Slurp::Tiny;
use File::Spec;
my $name = shift;
die "usage: $0 name file [file...]" unless $name && @ARGV;
my $pkgdir = "lib/Lido/XML/$name";
my @packages;
for my $path (@ARGV) {
my ($volume,$directories,$file) = File::Spec->splitpath( $path );
my $content = File::Slurp::Tiny::read_file($path);
my $package = $file;
$package =~ s{\..*$}{};
$package =~ s{[^A-Za-z0-9_]}{_}g;
$package =~ s{_+}{_}g;
print "$file -> $pkgdir/$package.pm\n";
File::Slurp::Tiny::write_file("$pkgdir/$package.pm",<<EOF);
package Lido::XML::$name\::$package;
use Moo;
our \$VERSION = '0.01';
sub content {
my \@lines = <DATA>;
join '' , \@lines;
}
1;
__DATA__
$content
EOF
push @packages , "Lido::XML::$name\::$package";
}
my $perl =<<EOF;
package Lido::XML::$name;
our \$VERSION = '0.01';
use Moo;
EOF
for my $pkg (@packages) {
$perl .=<<EOF;
use $pkg;
EOF
}
$perl .=<<EOF;
sub content {
my \@res;
for my \$pkg (qw(
EOF
for my $pkg (@packages) {
$perl .=<<EOF;
$pkg
EOF
}
$perl .=<<EOF;
)) {
push \@res , \$pkg->new->content;
}
\@res;
}
1;
EOF
File::Slurp::Tiny::write_file("$pkgdir.pm",$perl);