summaryrefslogtreecommitdiff
path: root/Master/tlpkg/TeXLive/TLPDB.pm
diff options
context:
space:
mode:
authorNorbert Preining <preining@logic.at>2017-10-13 06:50:59 +0000
committerNorbert Preining <preining@logic.at>2017-10-13 06:50:59 +0000
commit8b02c12ef1888a8819a0e33ba7449a522a87afba (patch)
treeab89d27f2388db37df6c125ceb678802a3dcccf1 /Master/tlpkg/TeXLive/TLPDB.pm
parentbea24bc71979f672b3580e56cefc931ebf964906 (diff)
tlmgr dump-tlpdb -json possible
git-svn-id: svn://tug.org/texlive/trunk@45532 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/TeXLive/TLPDB.pm')
-rw-r--r--Master/tlpkg/TeXLive/TLPDB.pm38
1 files changed, 38 insertions, 0 deletions
diff --git a/Master/tlpkg/TeXLive/TLPDB.pm b/Master/tlpkg/TeXLive/TLPDB.pm
index 1dcdb3b91cb..b34650c84e3 100644
--- a/Master/tlpkg/TeXLive/TLPDB.pm
+++ b/Master/tlpkg/TeXLive/TLPDB.pm
@@ -28,6 +28,7 @@ C<TeXLive::TLPDB> -- A database of TeX Live Packages
$tlpdb->from_file($filename);
$tlpdb->writeout;
$tlpdb->writeout(FILEHANDLE);
+ $tlpdb->as_json;
$tlpdb->save;
$tlpdb->media;
$tlpdb->available_architectures();
@@ -466,6 +467,43 @@ sub writeout {
=pod
+=item C<< $tlpdb->as_json >>
+
+The C<as_json> function returns a JSON UTF8 encoded representation of the
+database, that is a JSON array of packages. If the database is virtual,
+a JSON array where each element is a hash with two keys, C<tag> giving
+the tag of the sub-database, and C<tlpdb> giving the JSON of the database.
+
+=cut
+
+sub as_json {
+ my $self = shift;
+ my $ret;
+ if ($self->is_virtual) {
+ $ret = "[\n";
+ my $firsttlpdb = 1;
+ for my $k (keys %{$self->{'tlpdbs'}}) {
+ $ret .= ",\n" if (!$firsttlpdb);
+ $ret .= "{ \"tag\" : \"$k\", \"tlpdb\" : ";
+ $firsttlpdb = 0;
+ $ret .= $self->{'tlpdbs'}{$k}->as_json;
+ $ret .= " }";
+ }
+ $ret .= "\n]";
+ } else {
+ $ret = "[\n";
+ my $first = 1;
+ foreach (keys %{$self->{'tlps'}}) {
+ $ret .= ",\n" if (!$first);
+ $first = 0;
+ $ret .= $self->{'tlps'}{$_}->as_json;
+ }
+ $ret .= "\n]";
+ }
+}
+
+=pod
+
=item C<< $tlpdb->save >>
The C<save> functions saves the C<TLPDB> to the file which has been set