Amon2-CLI

 view release on metacpan or  search on metacpan

lib/Amon2/CLI.pm  view on Meta::CPAN

    }
}

1;

__END__

=encoding UTF-8

=head1 NAME

Amon2::CLI - The way of CLI for Amon2 App


=head1 SYNOPSIS

First of all, in your MyApp class

    package MyApp;
    use strict;
    use warnings;
    use parent qw/Amon2/;

    1;

Then in your MyApp::CLI::Foo class

    package MyApp::CLI::Foo;
    use strict;
    use warnings;

    sub main {
        my ($class, $c) = @_;
        # do something
        print 'done!';
    }

    1;

Finally, in your script

    use Amon2::CLI 'MyApp';

    MyApp->bootstrap->run('Foo'); # done!

Or directly,

    use Amon2::CLI 'MyApp';

    MyApp->bootstrap->run(sub{
        my ($c) = @_;
        # do something
        print 'kaboom!';
    });


=head1 DESCRIPTION

Amon2::CLI is B<ALPHA QUALITY>. B<I may change interfaces without a notice>.

This module gives you the easy way of CLI for Amon2 App. It handles to load class, to get options and to throw error.


=head1 CONFIGURE PLUGIN

You can write your own C<MyApp::CLI> class for customizing the way instead of C<Amon2::CLI>.

    package MyApp::CLI;
    use strict;
    use warnings;
    use parent qw/Amon2/;
    use MyApp::Logger;

    __PACKAGE__->load_plugins(
        'CLI' => {
            base => 'MyApp::CLI',
            on_error => sub {
                my ($c, $e) = @_;
                MyApp::Logger->write('path/to/log', $e);
            },
        },
    );

And in your script

    use MyApp::CLI;

    MyApp::CLI->bootstrap->run(sub{
        my ($c) = @_;
        # do something
        print 'OK!';
    });

=head2 PLUGIN OPTIONS

=head3 base

The base class name

=head3 on_error

The code ref for handling error

=head3 before_run

The code ref which is invoked before running main method

=head3 after_run

The code ref which is invoked after running main method

=head3 method // 'main'

The name of method in class for script

=head3 run_method // 'run'

The name of method on $c for invoking CLI script

=head3 getopt // [qw/:config posix_default no_ignore_case gnu_compat/]



( run in 0.704 second using v1.01-cache-2.11-cpan-5511b514fd6 )