AppWindow/BaseClasses/Plugin.pm

filter: Statementstmt 28.3% 17 / 60 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 27.7% 5 / 18 Podpod 72.7% 8 / 11 totaltotal 28.3% 30 / 106 CC 9 SCAR 18.9
CC
9
Cov
23%
new
20.0
Unload
12.0
AUTOLOAD
6.0
CRAP 6.6
« AppWindow/Ext/Selector.pm ↑ Summary AppWindow/BaseClasses/Extension.pm »
1 package Tk::AppWindow::BaseClasses::Plugin;
2  
3 =head1 NAME
4  
5 Tk::AppWindow::BaseClasses::Plugin - Baseclass for all plugins.
6  
7 =cut
8  
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 $VERSION="0.07";
14 2 ▶use vars '$AUTOLOAD';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 =head1 SYNOPSIS
17  
18 #This is useless
19 my $plug = Tk::AppWindow::BaseClasses::Plugin->new($frame);
20  
21 #This is what you should do
22 package My::App::Path::Plugins::MyPlugin
23 use base(Tk::AppWindow::BaseClasses::Plugin);
24 sub new {
25 my $class = shift;
26 my $self = $class->SUPER::new(@_); #$mainwindow should be the first in @_
27 if (defined $self) {
28 ...
29 }
30 return $self
31 }
32  
33 =head1 DESCRIPTION
34  
35 A plugin is different from an extension in a couple of ways:
36  
37 - A plugin can be loaded and unloaded by the end user.
38 If they do not desire the functionality they can simply
39 unload it.
40 - A plugin can not define config variables
41  
42 This is a base class you can inherit to write your own plugin.
43  
44 It autoloads methods from the mainwindow class.
45  
46 =cut
47  
48 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod undocumented
49 0 my ($proto, $window, @required) = (@_);
50 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
51 0 my $self = {
52 APPWINDOW => $window,
53 };
54 0 bless ($self, $class);
55 0 for (@required) {
56 0 ▶ unless ($self->extExists($_)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->extExists($_)) 0 0 0
57 0 croak "Extension $_ is not loaded";
58 return undef
59 0 }
60 }
61 0 $self->after(10, ['CheckSettingsPage', $self]);
62 0 return $self
63 }
64  
65 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=2 SCAR=17.9
66 0 my $self = shift;
67 0 ▶ return if $AUTOLOAD =~ /::DESTROY$/;
Branch: 1 branch
BranchTrueFalseTotal
if $Tk::AppWindow::BaseClasses::Plugin::AUTOLOAD =~ /::DESTROY$/ 0 0 0
68 0 $AUTOLOAD =~ s/^.*:://;
69 0 return $self->{APPWINDOW}->$AUTOLOAD(@_);
70 }
71  
72 0 ▶sub _getnb {
Subroutine _getnb: not called CC=2 SCAR=17.9
73 0 my $self = shift;
74 0 my $set = $self->extGet('Settings');
75 0 my $nb;
76 0 ▶ $nb = $set->NBWidget if defined $set;
Branch: 1 branch
BranchTrueFalseTotal
if defined $set 0 0 0
77 0 return $nb;
78 }
79  
80 =head1 METHODS
81  
82 =over 4
83  
84 =item B<CanQuit>
85  
86 Returns 1. It is there for you to overwrite. It is called when you attempt to close the window or execute the quit command.
87 Overwrite it to check for unsaved data and possibly veto these commands by returning a 0.
88  
89 =cut
90  
91 0 ▶sub CanQuit { return 1 }
Subroutine CanQuit: not called CC=1 SCAR=6.9
Pod documented
92  
93 0 ▶sub CheckSettingsPage {
Subroutine CheckSettingsPage: not called CC=2 SCAR=17.9
Pod undocumented
94 0 my $self = shift;
95 0 my $nb = $self->_getnb;
96 0 ▶ return unless defined $nb;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $nb 0 0 0
97 0 my $set = $self->extGet('Settings');
98 0 $set->externalAdd($self->SettingsPage);
99 }
100  
101 =item B<GetAppWindow>
102  
103 Returns a reference to the toplevel frame. The toplevel frame should be a Tk::AppWindow class.
104  
105 =cut
106  
107 0 ▶sub GetAppWindow { return $_[0]->{APPWINDOW} }
Subroutine GetAppWindow: not called CC=1 SCAR=6.9
Pod documented
108  
109 =item B<MenuItems>
110  
111 Returns and empty list. It is there for you to overwrite. It is called by the B<Plugins> extension. You can return a list
112 with menu items here. For details on the format see B<Tk::AppWindow::Ext::MenuBar>
113  
114 =cut
115  
116 0 ▶sub MenuItems {
Subroutine MenuItems: not called CC=1 SCAR=6.9
Pod documented
117 0 return ();
118 }
119  
120 =item B<Name>
121  
122 returns the module name of $self, without the path. So, if left uninherited, it returns 'Plugin'.
123  
124 =cut
125  
126 0 ▶sub Name {
Subroutine Name: not called CC=1 SCAR=6.9
Pod documented
127 0 my $self = shift;
128 0 my $name = ref $self;
129 0 $name =~ s/.*:://;
130 0 return $name
131 }
132  
133 =item B<ReConfigure>
134  
135 Does nothing. It is called when the user clicks the Apply button in the settings dialog. Overwrite it to act on
136 modified settings. It should return 0 or 1 depending on succes.
137  
138 =cut
139  
140 0 ▶sub ReConfigure {
Subroutine ReConfigure: not called CC=1 SCAR=6.9
Pod documented
141 0 return 1
142 }
143  
144 =item B<ToolItems>
145  
146 Returns and empty list. It is there for you to overwrite. It is called by the B<Plugins> extension. You can return a list
147 with menu items here. For details on the format see B<Tk::AppWindow::Ext::MenuBar>
148  
149 =cut
150  
151 =item B<SettingsPage>
152  
153 Returns an empty list. It is there for you to overwrite. It is called by the B<Plugins> extension.
154 You can return a paired list of pagenames and widget.
155  
156 sub SettingsPage {
157 . return (
158 'Some title' => ['MyWidget', @options],
159 )
160 }
161  
162 If 'MyWidget' has an 'Apply' method it will be called when you hit the 'Apply' button.
163  
164 =cut
165  
166 0 ▶sub SettingsPage {
Subroutine SettingsPage: not called CC=1 SCAR=6.9
Pod documented
167 0 return ();
168 }
169  
170 0 ▶sub ToolItems {
Subroutine ToolItems: not called CC=1 SCAR=6.9
Pod documented
171 0 return ();
172 }
173  
174 =item B<Quit>
175  
176 Does nothing. It is there for you to overwrite. Here you do everything needed when the application
177 is to terminate.
178  
179 =cut
180  
181 0 ▶sub Quit { }
Subroutine Quit: not called CC=1 SCAR=0.0
Pod documented
182  
183 =item B<UnLoad>
184  
185 Removes the settings page for this plugin from the settings dialog if applicable.
186 Returns 1. When overwriting this method, make a call to SUPER::Unload to include this. and do what
187 is needed to completely unload your plugin.
188  
189 =cut
190  
191 0 ▶sub Unload {
Subroutine Unload: not called CC=3 SCAR=24.8
Pod undocumented
192 0 my $self = shift;
193 0 my @sp = $self->SettingsPage;
194 0 my $set = $self->extGet('Settings');
195 0 ▶ if (defined $set) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $set) 0 0 0
196 0 ▶ while (@sp) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sp) 0 0 0
197 0 my $page = shift @sp;
198 0 $set->externalRemove($page);
199 shift @sp
200 0 }
201 }
202 0 return 1;
203 }
204  
205 =back
206  
207 =head1 AUTHOR
208  
209 Hans Jeuken (hanje at cpan dot org)
210  
211 =head1 BUGS
212  
213 Unknown. If you find any, please contact the author.
214  
215 =head1 SEE ALSO
216  
217 =over 4
218  
219 =item L<Tk::AppWindow::BaseClasses::Extension>
220  
221 =item L<Tk::AppWindow>
222  
223 =back
224  
225 =cut
226  
227 2 1;
228 __END__
« AppWindow/Ext/Selector.pm ↑ Summary AppWindow/BaseClasses/Extension.pm »