/usr/share/perl5/MooseX/App/Simple.pm is in libmoosex-app-perl 1.33-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | package MooseX::App::Simple;
# ============================================================================«
use 5.010;
use utf8;
use strict;
use warnings;
our $AUTHORITY = 'cpan:MAROS';
our $VERSION = 1.32;
use Moose::Exporter;
use MooseX::App::Exporter qw(app_usage app_description app_base app_fuzzy app_strict app_prefer_commandline option parameter command_short_description command_long_description command_usage command_strict);
use MooseX::App::Meta::Role::Attribute::Option;
use MooseX::App::Message::Envelope;
use Scalar::Util qw(blessed);
my ($IMPORT,$UNIMPORT,$INIT_META) = Moose::Exporter->build_import_methods(
with_meta => [ qw(app_usage app_description app_base app_fuzzy app_strict option parameter command_short_description command_long_description command_usage command_strict) ],
also => [ 'Moose' ],
as_is => [ 'new_with_options' ],
install => [ 'unimport', 'init_meta' ],
);
sub import {
my ( $class, @plugins ) = @_;
# Get caller
my ($caller_class) = caller();
# Process plugins
MooseX::App::Exporter->process_plugins($caller_class,@plugins);
# Call Moose-Exporter generated importer
return $class->$IMPORT( { into => $caller_class } );
}
sub init_meta {
my ($class,%args) = @_;
my $for_class = $args{for_class};
$args{roles} = ['MooseX::App::Role::Base' ];
$args{metaroles} = {
class => [
'MooseX::App::Meta::Role::Class::Base',
'MooseX::App::Meta::Role::Class::Simple',
'MooseX::App::Meta::Role::Class::Documentation'
],
attribute => [
'MooseX::App::Meta::Role::Attribute::Option'
],
};
my $meta = MooseX::App::Exporter->process_init_meta(%args);
$for_class->meta->app_commands({ 'self' => $for_class });
return $meta;
}
sub new_with_options {
my ($class,@args) = @_;
Moose->throw_error('new_with_options is a class method')
if ! defined $class || blessed($class);
my %args;
if (scalar @args == 1
&& ref($args[0]) eq 'HASH' ) {
%args = %{$args[0]};
} elsif (scalar @args % 2 == 0) {
%args = @args;
} else {
Moose->throw_error('new_with_command got invalid extra arguments');
}
my $parsed_argv = MooseX::App::ParsedArgv->instance();
return $class->initialize_command_class($class,%args);
}
no Moose;
1;
__END__
=encoding utf8
=head1 NAME
MooseX::App::Simple - Single command applications
=head1 SYNOPSIS
package MyApp;
use MooseX::App::Simple qw(Config Color);
parameter 'param' => (
is => 'rw',
isa => 'Str',
documentation => q[First parameter],
required => 1,
); # Positional parameter
option 'my_option' => (
is => 'rw',
isa => 'Bool',
documentation => q[Enable this to do fancy stuff],
); # Option (--my_option)
has 'private' => (
is => 'rw',
); # not exposed
sub run {
my ($self) = @_;
# Do something
}
And then in some simple wrapper script:
#!/usr/bin/env perl
use MyApp;
MyApp->new_with_options->run;
=head1 DESCRIPTION
MooseX-App-Simple works basically just as MooseX-App, however it does
not search for commands and assumes that you have all options and parameters
defined in the current class.
Read the L<Tutorial|MooseX::App::Tutorial> for getting started with a simple
MooseX::App command line application.
=head1 METHODS
=head2 new_with_options
my $myapp_command = MyApp->new_with_options();
This method reads the command line arguments from the user and tries to create
instantiate the current class with the ARGV-input. If it fails it retuns a
L<MooseX::App::Message::Envelope> object holding an error message.
You can pass a hash or hashref of default params to new_with_options
MyApp->new_with_options( %default );
=head1 OPTIONS
Same as in L<MooseX::App>
=head1 PLUGINS
Same as in L<MooseX::App>. However plugings adding commands (eg. version)
will not work with MooseX::App::Simple.
=head1 SEE ALSO
Read the L<Tutorial|MooseX::App::Tutorial> for getting started with a simple
MooseX::App command line application.
See L<MooseX::Getopt> and L<MooX::Options> for alternatives
=cut
|