line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::CLI::Extension::Component::InstallCallback; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
App::CLI::Extension::Component::InstallCallback - for App::CLI::Extension install callback module |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
1.421 |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# MyApp.pm |
16
|
|
|
|
|
|
|
package MyApp; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use strict; |
19
|
|
|
|
|
|
|
use base qw(App::CLI::Extension); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# MyApp/Hello.pm |
22
|
|
|
|
|
|
|
package MyApp::Hello; |
23
|
|
|
|
|
|
|
use strict; |
24
|
|
|
|
|
|
|
use feature ":5.10.0"; |
25
|
|
|
|
|
|
|
use base qw(App::CLI::Command); |
26
|
|
|
|
|
|
|
use constants options => ("runmode=s" => "runmode"); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub prerun { |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my($self, @argv) = @_; |
31
|
|
|
|
|
|
|
$self->new_callback("view", sub { |
32
|
|
|
|
|
|
|
my($self, @args) = @_; |
33
|
|
|
|
|
|
|
# anything view to do... |
34
|
|
|
|
|
|
|
foreach $list (@{$self->anything_all_list}) { |
35
|
|
|
|
|
|
|
printf "%d: %s\n", $list->id, $list->name; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
}); |
38
|
|
|
|
|
|
|
$self->new_callback("exec", sub { |
39
|
|
|
|
|
|
|
my($self, @args) = @_; |
40
|
|
|
|
|
|
|
# anything execute to do... |
41
|
|
|
|
|
|
|
$self->anything_execute(@args); |
42
|
|
|
|
|
|
|
}); |
43
|
|
|
|
|
|
|
$self->>maybe::next::method(@argv); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub run { |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my($self, @args) = @_; |
49
|
|
|
|
|
|
|
my $runmode = $self->{runmode}; |
50
|
|
|
|
|
|
|
if ($self->exists_callback($runmode)) { |
51
|
|
|
|
|
|
|
$self->exec_callback($runmode, @args); |
52
|
|
|
|
|
|
|
} else { |
53
|
|
|
|
|
|
|
die "invalid runmode!!"; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# myapp |
58
|
|
|
|
|
|
|
#!/usr/bin/perl |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
use strict; |
61
|
|
|
|
|
|
|
use MyApp; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
MyApp->dispatch; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# execute view callback |
66
|
|
|
|
|
|
|
[kurt@localhost ~] myapp hello --runmode=view |
67
|
|
|
|
|
|
|
1: melon |
68
|
|
|
|
|
|
|
2: banana |
69
|
|
|
|
|
|
|
. |
70
|
|
|
|
|
|
|
. |
71
|
|
|
|
|
|
|
. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
18
|
|
|
18
|
|
104
|
use strict; |
|
18
|
|
|
|
|
34
|
|
|
18
|
|
|
|
|
736
|
|
76
|
18
|
|
|
18
|
|
104
|
use base qw(Class::Accessor::Grouped); |
|
18
|
|
|
|
|
35
|
|
|
18
|
|
|
|
|
7627
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
__PACKAGE__->mk_group_accessors( "inherited" => "_install_callback" ); |
79
|
|
|
|
|
|
|
__PACKAGE__->_install_callback({}); |
80
|
|
|
|
|
|
|
our $VERSION = '1.421'; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub new_callback { |
83
|
|
|
|
|
|
|
|
84
|
1
|
|
|
1
|
0
|
16
|
my($self, $install, $callback) = @_; |
85
|
1
|
50
|
|
|
|
11
|
if ($self->exists_callback($install)) { |
86
|
0
|
|
|
|
|
0
|
die "already exists $install"; |
87
|
|
|
|
|
|
|
} |
88
|
1
|
|
|
|
|
98
|
$self->_install_callback->{$install} = []; |
89
|
1
|
50
|
|
|
|
65
|
$self->add_callback($install, $callback) if defined $callback; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub add_callback { |
93
|
|
|
|
|
|
|
|
94
|
2
|
|
|
2
|
0
|
81
|
my($self, $install, $callback) = @_; |
95
|
2
|
50
|
|
|
|
6
|
if (!$self->exists_callback($install)) { |
96
|
0
|
|
|
|
|
0
|
die "non install callback: $install"; |
97
|
|
|
|
|
|
|
} |
98
|
2
|
50
|
|
|
|
179
|
if(ref($callback) ne "CODE") { |
99
|
0
|
|
|
|
|
0
|
die "\$callback is not CODE"; |
100
|
|
|
|
|
|
|
} |
101
|
2
|
|
|
|
|
4
|
push @{$self->_install_callback->{$install}}, $callback; |
|
2
|
|
|
|
|
52
|
|
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub exec_callback { |
105
|
|
|
|
|
|
|
|
106
|
1
|
|
|
1
|
0
|
75
|
my($self, $install, @args) = @_; |
107
|
1
|
50
|
|
|
|
4
|
if (!$self->exists_callback($install)) { |
108
|
0
|
|
|
|
|
0
|
die "non install callback: $install"; |
109
|
|
|
|
|
|
|
} |
110
|
1
|
|
|
|
|
67
|
map { $self->$_(@args) } @{$self->_install_callback->{$install}}; |
|
2
|
|
|
|
|
71
|
|
|
1
|
|
|
|
|
29
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub exists_callback { |
114
|
|
|
|
|
|
|
|
115
|
5
|
|
|
5
|
0
|
15
|
my($self, $install) = @_; |
116
|
5
|
100
|
|
|
|
150
|
return exists $self->_install_callback->{$install} ? 1 : 0; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |