Group
Extension

Matches 13

MOP4Import-Declare ( H/HK/HKOBA/MOP4Import-Declare-0.071.tar.gz, HKOBA, 2025; MetaCPAN )
MOP4Import-Declare/Util/JSON_TYPE.pm ( view source; MetaCPAN )
l::JSON_TYPE;
use strict;
use warnings;

use constant DEBUG => $ENV{DEBUG_MOP4IMPORT};

use MOP4Import::Util qw/globref define_constant terse_dump/;

use MOP4Import::Opts qw/Opts/;

use Cpanel::JSON::
XS::Type;

our %JSON_TYPES; # It is too early to hide this.

BEGIN {
  my $CLS = 'Cpanel::JSON::XS::Type';

  foreach my $origTypeName (qw(int float string bool null)) {
    foreach my $suffix ('', '_
 '';

      my $typeName = $origTypeName . $suffix;
      my $lowerName = "JSON_TYPE_".$typeName;
      my $upperName = "JSON_TYPE_".uc($typeName);
      my $value = $CLS->$upperName;
      define_con
MOP4Import-Declare ( H/HK/HKOBA/MOP4Import-Declare-0.071.tar.gz, HKOBA, 2025; MetaCPAN )
MOP4Import-Declare/Base/CLI_JSON.pm ( view source; MetaCPAN )
#!/usr/bin/env perl
package MOP4Import::Base::CLI_JSON;
use strict;
use warnings;
use Carp ();

use constant DEBUG => $ENV{DEBUG_MOP4IMPORT};
BEGIN {
  print STDERR "Using (file '" . __FILE__ . "')\n"
is help message", json_type => 'string']
     , ['quiet' => doc => 'to be (somewhat) quiet', json_type => 'int']
     , ['scalar' => doc => "evaluate methods in scalar context", json_type => 'bool']
 
 ['output' => default => 'ndjson'
        , doc => "choose output serializer (ndjson/json/tsv/dump)"
        , json_type => 'string'
      ]
     , ['flatten'
        , json_type => 'bool'
      ]
   
MOP4Import-Declare ( H/HK/HKOBA/MOP4Import-Declare-0.071.tar.gz, HKOBA, 2025; MetaCPAN )
MOP4Import-Declare/Base/JSON.pm ( view source; MetaCPAN )
t::Base::JSON;
use strict;
use warnings;
use constant DEBUG => $ENV{DEBUG_MOP4IMPORT};

use MOP4Import::Base::Configure -as_base;

use JSON::MaybeXS;
use constant USING_CPANEL_JSON_XS => JSON()->isa("
ly works with Cpanel::JSON::XS. JSON::XS prohibits use of restricted hash.
sub TO_JSON {
  my ($self) = @_;
  +{map(($_ => $self->{$_}), grep {!/^_/} keys %$self)}
}

sub cli_json_type {
  (my MY $sel
f->cli_json_type_of($self);
}

sub cli_json_type_of {
  (my MY $self, my $objOrTypeName) = @_;
  $self->JSON_TYPE_HANDLER->lookup_json_type(ref $objOrTypeName || $objOrTypeName);
}

sub cli_json_encod
MOP4Import-Declare ( H/HK/HKOBA/MOP4Import-Declare-0.071.tar.gz, HKOBA, 2025; MetaCPAN )
MOP4Import-Declare/Opts.pm ( view source; MetaCPAN )
end of MOP4Import handling.
   , 'delayed_tasks'

   # default value for json_type. 'string' if not specified
   , 'default_json_type'

   # Cache to store and keep heavy computation results between p
MOP4Import-Declare ( H/HK/HKOBA/MOP4Import-Declare-0.071.tar.gz, HKOBA, 2025; MetaCPAN )
MOP4Import-Declare/intro_runnable_module.pod ( view source; MetaCPAN )
in C<undef>, C<[..]>, C<{..}>...
we must use some kind of serializer such as L<Data::Dumper> or L<JSON>.
Following is a minimum starting point of such subcommand dispatcher:


    use Data::Dumper;
  
is falsy.

=item *
Change output serializer to L<JSON>.

=item *
Change argument parser to convert C<[..]>, C<{...}> automatically
by L<JSON/decode_json> too.
This enables you to compose your favorite
h takes/returns structured objects/arrays.

=back

This is a backstory of L<MOP4Import::Base::CLI_JSON>. Thank you for reading!

=head1 APPENDIX

=head2 Sample implementation of parse_opts()


    sub
MOP4Import-Declare ( H/HK/HKOBA/MOP4Import-Declare-0.071.tar.gz, HKOBA, 2025; MetaCPAN )
MOP4Import-Declare/Declare.pm ( view source; MetaCPAN )
);
  my $fields_array = fields_array($opts->{objpkg});

  my $isFirst = not $myPack->JSON_TYPE_HANDLER->lookup_json_type($opts->{objpkg});

  # Import all fields from super class
  foreach my $super_c
gin->clone : $origin;
      };
      push @$fields_array, $name;
    }

    $myPack->JSON_TYPE_HANDLER->inherit_json_type($opts->{objpkg}, $super_class) if $isFirst;

  }

  {
    my %dup;
    foreach
c;
    }
  };

  print STDERR "  FieldSpec is: $field_class\n" if DEBUG;

  $myPack->JSON_TYPE_HANDLER->declare_json_type_record($opts->{objpkg});

  $myPack->declare___field($opts, $field_class, ref 
MOP4Import-Declare ( H/HK/HKOBA/MOP4Import-Declare-0.071.tar.gz, HKOBA, 2025; MetaCPAN )
MOP4Import-Declare/FieldSpec.pm ( view source; MetaCPAN )
 fields
  ('name'
   , 'doc' # documentation
   , 'default'
   , 'no_getter'
   , 'package'
   , 'json_type'
   , 'isa'
   , 'validator'
   , 'zsh_completer'
   , 'extra'
   # file? line? package?
 );
MOP4Import-Declare ( H/HK/HKOBA/MOP4Import-Declare-0.071.tar.gz, HKOBA, 2025; MetaCPAN )
MOP4Import-Declare/Util.pm ( view source; MetaCPAN )
esult : $result;
}

#
# posix_style long option with JSON support.
#
sub parse_json_opts {
  my ($pack, $list, $result, $alias) = @_;
  require JSON::MaybeXS;
  parse_opts($pack, $list, $result, $alia
d.
      my $copy = $_[0];
      Encode::_utf8_off($copy) if Encode::is_utf8($copy);
      JSON::MaybeXS::JSON()->new->utf8->relaxed->decode($copy);
    } elsif (not Encode::is_utf8($_[0]) and $_[0] =
MOP4Import-Declare ( H/HK/HKOBA/MOP4Import-Declare-0.071.tar.gz, HKOBA, 2025; MetaCPAN )
MOP4Import-Declare/Base/Configure.pm ( view source; MetaCPAN )
ates set hook (onconfigure_FIELDNAME) wrapped with
L<Scalar::Util/weaken>.

=head2 json_type => STRING | Cpanel::JSON::XS::Type

To be documented...

=head1 SEE ALSO

L<MOP4Import::Declare>

=head1 AU
MOP4Import-Declare ( H/HK/HKOBA/MOP4Import-Declare-0.071.tar.gz, HKOBA, 2025; MetaCPAN )
MOP4Import-Declare/Base/CLI_JSON.pod ( view source; MetaCPAN )
ase::CLI_JSON - Base class for rapidly building testable CLI modules with JSON I/O

=head1 SYNOPSIS

=for code perl

  #!/usr/bin/env perl
  package MyScript;

  use MOP4Import::Base::CLI_JSON -as_bas
 [fields =>
        [verbose => doc => "Enable verbose output", json_type => 'bool'],
        [config  => doc => "Config file path", json_type => 'string']
      ];

  MY->cli_run(\@ARGV) unless calle
K\n";
  }

  # Regular method - output handled by CLI_JSON
  sub query {
    my ($self, $sql) = @_;
    # Returns data structure that will be JSON-encoded
    return {result => "data from $sql"};
  }
MOP4Import-Declare ( H/HK/HKOBA/MOP4Import-Declare-0.071.tar.gz, HKOBA, 2025; MetaCPAN )
MOP4Import-Declare/Util/Inspector.pm ( view source; MetaCPAN )
t STDERR "Using (file '" . __FILE__ . "')\n" if DEBUG and DEBUG >= 2
}

use MOP4Import::Base::CLI_JSON -as_base
  , [fields =>
     [lib =>
      doc => "library directory list. SCALAR, ARRAY or ':' s
MOP4Import-Declare ( H/HK/HKOBA/MOP4Import-Declare-0.071.tar.gz, HKOBA, 2025; MetaCPAN )
MOP4Import-Declare/Util/CommentedJson.pm ( view source; MetaCPAN )
ackage MOP4Import::Util::CommentedJson;
use strict;
use warnings FATAL => 'all';
use Exporter qw/import/;
use JSON::MaybeXS;
use bytes;

our @EXPORT_OK = qw/strip_json_comments/;

our $re_atom = qr{tr
tring
              }xs;

sub strip_json_comments {
  my ($pack, $bytes) = @_;
  $bytes =~ s/\A\xef\xbb\xbf//; # Strip BOM of utf-8.
  my @region = reverse list_json_comments($pack, $bytes);
  foreach
 ($startPos, $len) = @$region;
    substr($bytes, $startPos, $len, '');
  }
  $bytes;
}

sub list_json_comments {
  my @pos;
  while ($_[1] =~ m{\G(?<ws>\s*+)$re_ALL}g) {
    if (defined $+{comment} a
MOP4Import-Declare ( H/HK/HKOBA/MOP4Import-Declare-0.071.tar.gz, HKOBA, 2025; MetaCPAN )
MOP4Import-Declare/Base/CLI.pod ( view source; MetaCPAN )
i_run(\@ARGV) unless caller;
  1;


=head1 DESCRIPTION

Now superceded by L<MOP4Import::Base::CLI_JSON>.

MOP4Import::Base::CLI is a general purpose base class to make
L<your module also runnable from

Powered by Groonga
Maintained by Kenichi Ishigaki <ishigaki@cpan.org>. If you find anything, submit it on GitHub.