File: demo-simple.pl

package info (click to toggle)
libcli-framework-perl 0.05-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 460 kB
  • ctags: 282
  • sloc: perl: 2,168; sql: 18; sh: 3; makefile: 2
file content (61 lines) | stat: -rw-r--r-- 1,272 bytes parent folder | download | duplicates (2)
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
use strict;
use warnings;

use lib 'lib';

# ---- EXECUTION ----
# Here, we set the default command to the only command in our simple
# application.  If this is not done, 'help' will be the default.
my $app = Converted::Script->new();
$app->set_default_command( 'legacy-script' );
$app->run();

###################################

# ---- APPLICATION ----
package Converted::Script;
use base qw( CLI::Framework );

use strict;
use warnings;

sub usage_text {
    qq{
    $0 [--verbose|v] [--help|h]: work all manner of mischief devised by long-departed miscreants
    }
}

sub option_spec {
    [ 'help|h'      => 'show help' ],
    [ 'verbose|v'   => 'be verbose' ],
}

sub command_map {
    'legacy-script' => 'Converted::Script::Command::LegacyScript',
}

# ---- COMMAND ----
package Converted::Script::Command::LegacyScript;
use base qw( CLI::Framework::Command );

use strict;
use warnings;

sub run {
    # Now that the extraneous details have been separated into their own
    # subroutines, run() contains just the "real" program logic.
    my ($self, $opts, @args) = @_;

    return 'running '.__PACKAGE__.
    "... (<useful things happen here -- use your imagination>)\n";
}

__END__

=pod

=head1 PURPOSE

Demonstration of a very simple CLIF application.

=cut