line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CTK::Plugin; |
2
|
3
|
|
|
3
|
|
20
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
73
|
|
3
|
3
|
|
|
3
|
|
13
|
use utf8; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
10
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=encoding utf-8 |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
CTK::Plugin - Base class for CTK plugins writing |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version 1.01 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package CTK::Plugin::Foo; |
18
|
|
|
|
|
|
|
use strict; |
19
|
|
|
|
|
|
|
use base qw/CTK::Plugin/; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub init { |
22
|
|
|
|
|
|
|
my $self = shift; # It is CTK object! |
23
|
|
|
|
|
|
|
... |
24
|
|
|
|
|
|
|
return 1; # or 0 if errors |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
__PACKAGE__->register_method( |
28
|
|
|
|
|
|
|
namespace => "CTK", # Optional. Default: CTK |
29
|
|
|
|
|
|
|
method => "foo", |
30
|
|
|
|
|
|
|
callback => sub { |
31
|
|
|
|
|
|
|
my $self = shift; # It is CTK object! |
32
|
|
|
|
|
|
|
... |
33
|
|
|
|
|
|
|
return 1; |
34
|
|
|
|
|
|
|
}); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
1; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 DESCRIPTION |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
A "plugin" for the CTK is simply a Perl module which exists in a known package |
41
|
|
|
|
|
|
|
location (CTK::Plugin::*) and conforms to a our standard, allowing it to be |
42
|
|
|
|
|
|
|
loaded and used automatically. See L for example |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 init |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Allows you to initialize your plugin |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
The method is automatically call in CTK constructor. The first param is CTK object. |
49
|
|
|
|
|
|
|
The method MUST return 0 in case of failure or 1 in case of successful initialization |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 register_method |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__PACKAGE__->register_method( |
54
|
|
|
|
|
|
|
namespace => "CTK", # Optional. Default: CTK |
55
|
|
|
|
|
|
|
method => "mothod_name", |
56
|
|
|
|
|
|
|
callback => sub { |
57
|
|
|
|
|
|
|
my $self = shift; # It is CTK object! |
58
|
|
|
|
|
|
|
... |
59
|
|
|
|
|
|
|
return 1; |
60
|
|
|
|
|
|
|
}); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Allows register the method that will be linked with Your plugin callback function |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 HISTORY |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=over 8 |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item B<1.00 Wed 1 May 00:20:20 MSK 2019> |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Init version |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=back |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
See C file |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 TO DO |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
See C file |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 BUGS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
* none noted |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 SEE ALSO |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
L |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 AUTHOR |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Serż Minus (Sergey Lepenkov) L Eabalama@cpan.orgE |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 COPYRIGHT |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Copyright (C) 1998-2022 D&D Corporation. All Rights Reserved |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 LICENSE |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
99
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
See C file and L |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
3
|
|
|
3
|
|
100
|
use vars qw/ $VERSION /; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
123
|
|
106
|
|
|
|
|
|
|
$VERSION = '1.01'; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
use constant { |
109
|
3
|
|
|
|
|
603
|
NAMESPACE => "CTK", |
110
|
3
|
|
|
3
|
|
16
|
}; |
|
3
|
|
|
|
|
6
|
|
111
|
|
|
|
|
|
|
|
112
|
2
|
|
|
2
|
1
|
6
|
sub init { 1 } |
113
|
|
|
|
|
|
|
sub register_method { |
114
|
40
|
|
|
40
|
1
|
61
|
my $package = shift; |
115
|
40
|
|
|
|
|
93
|
my %meta = @_; |
116
|
40
|
|
100
|
|
|
120
|
my $namespace = $meta{namespace} || NAMESPACE; |
117
|
40
|
|
50
|
0
|
|
76
|
my $callback = $meta{callback} || sub { 1 }; |
|
0
|
|
|
|
|
|
|
118
|
40
|
50
|
|
|
|
75
|
return unless ref($callback) eq "CODE"; |
119
|
40
|
|
|
|
|
47
|
my $method = $meta{method}; |
120
|
40
|
50
|
|
|
|
100
|
return unless $method; |
121
|
40
|
|
|
|
|
111
|
my $ff = sprintf("%s::%s", $namespace, $method); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# Check |
124
|
3
|
50
|
|
3
|
|
21
|
return if do { no strict 'refs'; defined &{$ff} }; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
153
|
|
|
40
|
|
|
|
|
44
|
|
|
40
|
|
|
|
|
43
|
|
|
40
|
|
|
|
|
178
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# Create method! |
127
|
40
|
|
|
|
|
55
|
do { |
128
|
3
|
|
|
3
|
|
16
|
no strict 'refs'; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
201
|
|
129
|
40
|
|
|
|
|
49
|
*{$ff} = \&$callback; |
|
40
|
|
|
|
|
153
|
|
130
|
|
|
|
|
|
|
}; |
131
|
40
|
|
|
|
|
89
|
return 1; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
__END__ |