| 1 | package Tk::AppWindow::BaseClasses::Extension; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | Tk::AppWindow::BaseClasses::Extension - Baseclass for all extensions in this framework | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | =cut | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | ▶ | use vars qw($VERSION $AUTOLOAD); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 1 | $VERSION="0.08"; | |||||||||||||||||||
| 13 | 1 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | #This is useless | ||||||||||||||||||||
| 18 | my $ext = Tk::AppWindow::BaseClasses::Extension->new($mainwindow); | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | #This is what you should do | ||||||||||||||||||||
| 21 | package Tk::AppWindow::Ext::MyExtension | ||||||||||||||||||||
| 22 | use base(Tk::AppWindow::BaseClasses::Extension); | ||||||||||||||||||||
| 23 | sub new { | ||||||||||||||||||||
| 24 | my $class = shift; | ||||||||||||||||||||
| 25 | my $self = $class->SUPER::new(@_); #$mainwindow should be the first in @_ | ||||||||||||||||||||
| 26 | ... | ||||||||||||||||||||
| 27 | return $self | ||||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | =head1 DESCRIPTION | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | Tk::AppWindow::BaseClasses::Extension is the base object for all extenstions in this Tk::AppWindow framework. All extensions inherit | ||||||||||||||||||||
| 33 | this class. It has access to the Tk::AppWindow object and autoloads its methods. | ||||||||||||||||||||
| 34 | It has the core mechanisms in place if your extensions need to reconfigure or veto a close command. | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | Use this class as a basis to define your own extension. | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | =cut | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 41 | 0 | my ($proto, $window) = (@_); | |||||||||||||||||||
| 42 | 0 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 43 | 0 | my $self = { | |||||||||||||||||||
| 44 | APPWINDOW => $window, | ||||||||||||||||||||
| 45 | }; | ||||||||||||||||||||
| 46 | 0 | bless ($self, $class); | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 0 | return $self; | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 52 | 0 | my $self = shift; | |||||||||||||||||||
| 53 | 0 | ▶ | return if $AUTOLOAD =~ /::DESTROY$/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | 0 | $AUTOLOAD =~ s/^.*:://; | |||||||||||||||||||
| 55 | 0 | return $self->{APPWINDOW}->$AUTOLOAD(@_); | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | =head1 METHODS | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | =over 4 | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | =item B<CanQuit> | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | Returns 1. It is there for you to overwrite. It is called when you attempt to close the window or execute the quit command. | ||||||||||||||||||||
| 65 | Overwrite it to check for unsaved data and possibly veto these commands by returning a 0. | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | =cut | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 0 | ▶ | sub CanQuit { return 1 } | ||||||||||||||||||
|
Subroutine
CanQuit: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | =item B<GetAppWindow> | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | Returns a reference to the MainWindow widget. | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | =cut | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 0 | ▶ | sub GetAppWindow { return $_[0]->{APPWINDOW} } | ||||||||||||||||||
|
Subroutine
GetAppWindow: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | =item B<MenuItems> | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | Returns an empty list. It is there for you to overwrite. It is called by the B<MenuBar> extension. You can return a list | ||||||||||||||||||||
| 82 | with menu items here. For details on the format see L<Tk::AppWindow::Ext::MenuBar> | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | =cut | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 0 | ▶ | sub MenuItems { | ||||||||||||||||||
|
Subroutine
MenuItems: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 87 | 0 | return (); | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | =item B<Name> | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | returns the module name of $self, without the path. So, if left uninherited, it returns 'Extension'. | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | =cut | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 0 | ▶ | sub Name { | ||||||||||||||||||
|
Subroutine
Name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 97 | 0 | my $self = shift; | |||||||||||||||||||
| 98 | 0 | my $name = ref $self; | |||||||||||||||||||
| 99 | 0 | $name =~ s/.*:://; | |||||||||||||||||||
| 100 | 0 | return $name | |||||||||||||||||||
| 101 | } | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | =item B<ReConfigure> | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | Does nothing. It is called when the user clicks the Apply button in the settings dialog. Overwrite it to act on | ||||||||||||||||||||
| 106 | modified settings. | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 0 | ▶ | sub ReConfigure {} | ||||||||||||||||||
|
Subroutine
ReConfigure: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | =item B<Require>I<(@extensions)> | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | Only call this during extension construction. | ||||||||||||||||||||
| 115 | Loads @extensions. ignores already loaded ones. | ||||||||||||||||||||
| 116 | returns true on succes. | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | =cut | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 0 | ▶ | sub Require { | ||||||||||||||||||
|
Subroutine
Require: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 121 | 0 | my $self = shift; | |||||||||||||||||||
| 122 | 0 | my $args = $self->GetArgsRef; | |||||||||||||||||||
| 123 | 0 | my $success = 1; | |||||||||||||||||||
| 124 | 0 | ▶ | while (@_) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 125 | 0 | my $m = shift; | |||||||||||||||||||
| 126 | 0 | ▶ | unless ($self->extExists($m)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 127 | 0 | $self->extLoad($m, $args); | |||||||||||||||||||
| 128 | 0 | ▶ | $success = '' unless $self->extExists($m); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 129 | } | ||||||||||||||||||||
| 130 | } | ||||||||||||||||||||
| 131 | 0 | return $success | |||||||||||||||||||
| 132 | } | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | =item B<SettingsPage> | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | Returns an empty list. It is there for you to overwrite. It is called by the B<Settings> extension. | ||||||||||||||||||||
| 137 | You can return a paired list of pagenames and widget. | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | sub SettingsPage { | ||||||||||||||||||||
| 140 | . return ( | ||||||||||||||||||||
| 141 | 'Some title' => ['MyWidget', @options], | ||||||||||||||||||||
| 142 | ) | ||||||||||||||||||||
| 143 | } | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | If 'MyWidget' has an 'Apply' method it will be called when you hit the 'Apply' button. | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | =cut | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | 0 | ▶ | sub SettingsPage { | ||||||||||||||||||
|
Subroutine
SettingsPage: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 150 | 0 | return (); | |||||||||||||||||||
| 151 | } | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | =item B<ToolItems> | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | Returns and empty list. It is there for you to overwrite. It is called by the | ||||||||||||||||||||
| 156 | B<ToolBar> extension. You can return a list with menu items here. For details | ||||||||||||||||||||
| 157 | on the format see L<Tk::AppWindow::Ext::ToolBar> | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | =cut | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | 0 | ▶ | sub ToolItems { | ||||||||||||||||||
|
Subroutine
ToolItems: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 162 | 0 | return (); | |||||||||||||||||||
| 163 | } | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | =item B<Quit> | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | Does nothing. It is there for you to overwrite. Here you do everything needed to terminate. | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | =cut | ||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | 0 | ▶ | sub Quit { } | ||||||||||||||||||
|
Subroutine
Quit: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | =back | ||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | =head1 AUTHOR | ||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | Hans Jeuken (hanje at cpan dot org) | ||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | =head1 BUGS | ||||||||||||||||||||
| 180 | |||||||||||||||||||||
| 181 | Unknown. If you find any, please contact the author. | ||||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | =head1 SEE ALSO | ||||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | =over 4 | ||||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | =item L<Tk::AppWindow> | ||||||||||||||||||||
| 188 | |||||||||||||||||||||
| 189 | =back | ||||||||||||||||||||
| 190 | |||||||||||||||||||||
| 191 | =cut | ||||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | 1 | 1; | |||||||||||||||||||
| 194 | __END__ | ||||||||||||||||||||