line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooX::Options::Actions; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
16382
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
348
|
use Import::Into; |
|
1
|
|
|
|
|
2339
|
|
|
1
|
|
|
|
|
84
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.001'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
MooX::Options::Actions - Instant one class CLI App |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
In MyApp::Script: |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package MyApp::Script; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use MooX::Options::Actions; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
option 'boo' => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
format => 's', |
25
|
|
|
|
|
|
|
required => 1, |
26
|
|
|
|
|
|
|
doc => "Surprise!" |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub cmd_dump { |
30
|
|
|
|
|
|
|
my ( $self ) = @_; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
print "Message: [" . $self->boo . "]\n"; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
1; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
In script.pl: |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
#! /usr/bin/env perl |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
use strict; |
42
|
|
|
|
|
|
|
use warnings; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
use MyApp::Script; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
MyApp::Script->new_with_actions; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
On the command line: |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$ ./script.pl dump --boo Hello |
51
|
|
|
|
|
|
|
Message: [Hello] |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 DESCRIPTION |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
MooX::Options::Actions is a set of packages designed to make setting up and |
56
|
|
|
|
|
|
|
creating command line applications really easy. It automatically imports Moo, |
57
|
|
|
|
|
|
|
MooX::Options, namespace::clean, and a |
58
|
|
|
|
|
|
|
L function to set up the top |
59
|
|
|
|
|
|
|
level commands. this means you only need to include this one module, and then |
60
|
|
|
|
|
|
|
you can set up options as from L, and set up commands to act on |
61
|
|
|
|
|
|
|
those options by creating subroutines with the C prefix. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub import { |
66
|
2
|
|
|
2
|
|
136
|
my $target = caller; |
67
|
2
|
|
|
|
|
47
|
Moo->import::into($target); |
68
|
2
|
|
|
|
|
11320
|
MooX::Options->import::into($target, protect_argv => 0 ); |
69
|
2
|
|
|
|
|
85892
|
namespace::clean->import::into( |
70
|
|
|
|
|
|
|
$target, |
71
|
|
|
|
|
|
|
-except => [ qw/ _options_data _options_config / ], |
72
|
|
|
|
|
|
|
); |
73
|
2
|
|
|
|
|
8881
|
MooX::Options::Actions::Builder->import::into($target, qw/ new_with_actions /); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 AUTHOR |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Tom Bloor Et.bloor@shadowcat.co.ukE |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 COPYRIGHT |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Copyright 2017- Tom Bloor |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 LICENSE |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
87
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 SEE ALSO |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
L L |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |