#!/usr/bin/env perl

=for Copyright
 .
 Copyright (c) 2008-2019 Bruce Ravel (L<http://bruceravel.github.io/home>).
 All rights reserved.
 .
 This file is free software; you can redistribute it and/or
 modify it under the same terms as Perl itself. See The Perl
 Artistic License.
 .
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

=cut

use Demeter qw(:hephaestus);

my ($prjfile, $jsonfile)  = @ARGV;

die "usage:\tprj2json prjfile jsonfile\n"               if not $prjfile or not $jsonfile;

die "'$prjfile' does not exist\n"                       if not -e $prjfile;
die "'$prjfile' cannot be read\n"                       if not -r $prjfile;
die "'$prjfile' is already a JSON-style project file\n" if Demeter->is_json($prjfile);
die "'$prjfile' is not an Athena project file\n"        if not Demeter->is_prj($prjfile);


my $prj = Demeter::Data::Prj->new(file=>$prjfile);
my @data = $prj->slurp;
Demeter->co->set_default('athena', 'project_format', 'json');
$data[0]->write_athena($jsonfile, @data);

print "$prjfile (original) ----> $jsonfile (JSON)\n";


=head1 NAME

prj2json - convert an original-style Athena project file to JSON-style

=head1 VERSION

This documentation refers to Demeter version 0.9.26.

=head1 SYNOPSIS

  prj2json originalstyle.prj jsonstyle.prj

=head1 DESCRIPTION

This program slurps in the contents of an original style project file
and exports it as a JSON-style file.

=head1 DEPENDENCIES

This uses L<Demeter> and its dependencies.

=head1 BUGS AND LIMITATIONS

Please report problems to the Ifeffit Mailing List
(L<http://cars9.uchicago.edu/mailman/listinfo/ifeffit/>)

Patches are welcome.

=head1 AUTHOR

Bruce Ravel (L<http://bruceravel.github.io/home>)

L<http://bruceravel.github.io/demeter/>

=head1 LICENCE AND COPYRIGHT

Copyright (c) 2006-2019 Bruce Ravel (L<http://bruceravel.github.io/home>). All rights reserved.

This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlgpl>.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

=cut
