diff options
author | Norbert Preining <preining@logic.at> | 2017-10-13 06:50:59 +0000 |
---|---|---|
committer | Norbert Preining <preining@logic.at> | 2017-10-13 06:50:59 +0000 |
commit | 8b02c12ef1888a8819a0e33ba7449a522a87afba (patch) | |
tree | ab89d27f2388db37df6c125ceb678802a3dcccf1 /Master/tlpkg | |
parent | bea24bc71979f672b3580e56cefc931ebf964906 (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')
-rw-r--r-- | Master/tlpkg/TeXLive/TLPDB.pm | 38 | ||||
-rw-r--r-- | Master/tlpkg/TeXLive/TLPOBJ.pm | 4 |
2 files changed, 42 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 diff --git a/Master/tlpkg/TeXLive/TLPOBJ.pm b/Master/tlpkg/TeXLive/TLPOBJ.pm index 77f2290e442..3e603bc99a3 100644 --- a/Master/tlpkg/TeXLive/TLPOBJ.pm +++ b/Master/tlpkg/TeXLive/TLPOBJ.pm @@ -1585,6 +1585,10 @@ or the filehandle if given: debugging function for comparison with C<tpm>/C<tlps>, will go away. +=item C<as_json> + +returns the representation of the C<TLPOBJ> in JSON format. + =item C<common_texmf_tree> if all files of the package are from the same texmf tree, this tree |