App-Toolforge-MixNMatch
view release on metacpan or search on metacpan
MixNMatch.pm view on Meta::CPAN
package App::Toolforge::MixNMatch;
use strict;
use warnings;
use Error::Pure qw(err);
use Getopt::Std;
use IO::Barf qw(barf);
use JSON::XS;
use LWP::Simple qw(get);
use Perl6::Slurp qw(slurp);
use Readonly;
use Toolforge::MixNMatch::Diff;
use Toolforge::MixNMatch::Print::Catalog;
use Toolforge::MixNMatch::Struct::Catalog;
use Unicode::UTF8 qw(encode_utf8);
# Constants
Readonly::Scalar our $URI_BASE => 'https://mix-n-match.toolforge.org/';
Readonly::Scalar our $URI_CATALOG_DETAIL => $URI_BASE.'api.php?query=catalog_details&catalog=%s';
our $VERSION = 0.06;
# Constructor.
sub new {
my ($class, @params) = @_;
# Create object.
my $self = bless {}, $class;
# Object.
return $self;
}
sub _catalog_json_file_to_obj {
my $json_file = shift;
my $json = slurp($json_file);
my $struct_hr = decode_json($json);
my $obj = Toolforge::MixNMatch::Struct::Catalog::struct2obj($struct_hr->{'data'});
return $obj;
}
sub _command_diff {
my ($json_file1, $json_file2, $print_options) = @_;
if (! defined $json_file1 || ! -r $json_file1) {
return (1, "Doesn't exist JSON file #1 for diff.");
}
if (! defined $json_file2 || ! -r $json_file2) {
return (1, "Doesn't exist JSON file #2 for diff.");
}
my $opts_hr = _process_print_options($print_options);
my $obj1 = _catalog_json_file_to_obj($json_file1);
my $obj2 = _catalog_json_file_to_obj($json_file2);
my $diff = Toolforge::MixNMatch::Diff::diff($obj1, $obj2);
my $ret = Toolforge::MixNMatch::Print::Catalog::print($diff, $opts_hr);
print encode_utf8($ret)."\n";
return (0, undef);
}
sub _command_download {
my ($catalog_id, $output_file) = @_;
MixNMatch.pm view on Meta::CPAN
=head1 SYNOPSIS
use App::Toolforge::MixNMatch;
my $obj = App::Toolforge::MixNMatch->new;
$obj->run;
=head1 METHODS
=over 8
=item C<new()>
Constructor.
=item C<run()>
Run.
=back
=head1 ERRORS
new():
From Class::Utils:
Unknown parameter '%s'.
=head1 EXAMPLE
use strict;
use warnings;
use App::Toolforge::MixNMatch;
# Run.
exit App::Toolforge::MixNMatch->new->run;
# Output:
# Usage: ./examples/ex1.pl [-h] [--version] [command] [command_args ..]
# -h Print help.
# --version Print version.
# command Command (diff, download, print).
#
# command 'diff' arguments:
# json_file1 - JSON file #1
# json_file2 - JSON file #2
# [print_options] - Print options (type, count, year_months, users)
# command 'download' arguments:
# catalog_id - Catalog ID
# [output_file] - Output file (default is catalog_id.json)
# command 'print' arguments:
# json_file or catalog_id - Catalog ID or JSON file
# [print_options] - Print options (type, count, year_months, users)
=head1 DEPENDENCIES
L<Error::Pure>,
L<Getopt::Std>,
L<IO::Barf>,
L<JSON::XS>,
L<LWP::Simple>,
L<Perl6::Slurp>,
L<Readonly>,
L<Toolforge::MixNMatch::Diff>,
L<Toolforge::MixNMatch::Print::Catalog>,
L<Toolforge::MixNMatch::Struct::Catalog>,
L<Unicode::UTF8>.
=head1 REPOSITORY
L<https://github.com/tupinek/App-Toolforge-MixNMatch>.
=head1 AUTHOR
Michal Josef Å paÄek L<mailto:skim@cpan.org>
L<http://skim.cz>
=head1 LICENSE AND COPYRIGHT
© 2020-2024 Michal Josef Å paÄek
BSD 2-Clause License
=head1 VERSION
0.06
=cut
( run in 0.763 second using v1.01-cache-2.11-cpan-59e3e3084b8 )