| 1 | package Tk::AppWindow::BaseClasses::PluginJobs; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Tk::AppWindow::BaseClasses::PluginJobs - Baseclass for plugins using background jobs. | ||||||||||
| 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); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | $VERSION="0.07"; | |||||||||
| 13 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 1 | ▶ | use base qw( Tk::AppWindow::BaseClasses::Plugin ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||
| 18 | |||||||||||
| 19 | #This is useless | ||||||||||
| 20 | my $plug = Tk::AppWindow::BaseClasses::PluginJobs->new($frame); | ||||||||||
| 21 | |||||||||||
| 22 | #This is what you should do | ||||||||||
| 23 | package My::App::Path::Plugins::MyPlugin | ||||||||||
| 24 | use base(Tk::AppWindow::BaseClasses::PluginJobs); | ||||||||||
| 25 | sub new { | ||||||||||
| 26 | my $class = shift; | ||||||||||
| 27 | my $self = $class->SUPER::new(@_); #$mainwindow should be the first in @_ | ||||||||||
| 28 | ... | ||||||||||
| 29 | return $self | ||||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | =head1 DESCRIPTION | ||||||||||
| 33 | |||||||||||
| 34 | This is a base class for plugins using the B<Daemons> extension for background jobs. | ||||||||||
| 35 | Make sure you have loaded the B<Daemons> extension. | ||||||||||
| 36 | |||||||||||
| 37 | All job names are made unique to Daemons by adding the name of the plugin at the end of the I<$name> you see in this document. | ||||||||||
| 38 | |||||||||||
| 39 | =head1 METHODS | ||||||||||
| 40 | |||||||||||
| 41 | =over 4 | ||||||||||
| 42 | |||||||||||
| 43 | =cut | ||||||||||
| 44 | |||||||||||
| 45 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 46 | 0 | my $class = shift; | |||||||||
| 47 | 0 | my $self = $class->SUPER::new(@_, 'Daemons'); | |||||||||
| 48 | 0 | ▶ | return undef unless defined $self; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | |||||||||||
| 50 | 0 | $self->{INTERVAL} = 100; | |||||||||
| 51 | |||||||||||
| 52 | 0 | return $self; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | sub _daem { | ||||||||
|
Subroutine
_daem: not called CC=1 SCAR=6.9
| |||||||||||
| 56 | 0 | return $_[0]->extGet('Daemons') | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | =item B<interval>I(?$interval?> | ||||||||||
| 60 | |||||||||||
| 61 | Sets and gets the interval for jobs. Default value 100. To clarify, in miliseconds | ||||||||||
| 62 | that would be 100 times the interval value of the B<Daemons> extension. | ||||||||||
| 63 | |||||||||||
| 64 | =cut | ||||||||||
| 65 | |||||||||||
| 66 | 0 | ▶ | sub interval { | ||||||||
|
Subroutine
interval: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 67 | 0 | my $self = shift; | |||||||||
| 68 | 0 | ▶ | $self->{INTERVAL} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | return $self->{INTERVAL} | ||||||||||
| 70 | 0 | } | |||||||||
| 71 | |||||||||||
| 72 | =item B<jobEnd>I<($name)> | ||||||||||
| 73 | |||||||||||
| 74 | =cut | ||||||||||
| 75 | |||||||||||
| 76 | 0 | ▶ | sub jobEnd { | ||||||||
|
Subroutine
jobEnd: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 77 | 0 | my ($self, $name) = @_; | |||||||||
| 78 | 0 | ▶ | croak 'Name not defined' unless defined $name; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 0 | $name = $name . $self->Name; | |||||||||
| 80 | 0 | $self->_daem->jobRemove($name); | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | =item B<jobExists>I<($name)> | ||||||||||
| 84 | |||||||||||
| 85 | =cut | ||||||||||
| 86 | |||||||||||
| 87 | 0 | ▶ | sub jobExists { | ||||||||
|
Subroutine
jobExists: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 88 | 0 | my ($self, $name) = @_; | |||||||||
| 89 | 0 | $name = $name . $self->Name; | |||||||||
| 90 | 0 | return $self->_daem->jobExists($name) | |||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | =item B<jobList> | ||||||||||
| 94 | |||||||||||
| 95 | =cut | ||||||||||
| 96 | |||||||||||
| 97 | 0 | ▶ | sub jobList { | ||||||||
|
Subroutine
jobList: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 98 | 0 | my $self = shift; | |||||||||
| 99 | 0 | my @l = $self->_daem->jobList; | |||||||||
| 100 | 0 | my @o = (); | |||||||||
| 101 | 0 | my $xt = quotemeta($self->Name); | |||||||||
| 102 | 0 | for (@l) { | |||||||||
| 103 | 0 | my $n = $_; | |||||||||
| 104 | 0 | ▶ | push @o, $n if $n =~ s/$xt$// | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | } | ||||||||||
| 106 | 0 | return @o; | |||||||||
| 107 | } | ||||||||||
| 108 | |||||||||||
| 109 | =item B<jobPause>I<($name)> | ||||||||||
| 110 | |||||||||||
| 111 | =cut | ||||||||||
| 112 | |||||||||||
| 113 | 0 | ▶ | sub jobPause { | ||||||||
|
Subroutine
jobPause: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 114 | 0 | my ($self, $name) = @_; | |||||||||
| 115 | 0 | $name = $name . $self->Name; | |||||||||
| 116 | 0 | $self->_daem->jobPause($name); | |||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | =item B<jobRestart>I<($name)> | ||||||||||
| 120 | |||||||||||
| 121 | =cut | ||||||||||
| 122 | |||||||||||
| 123 | 0 | ▶ | sub jobRestart { | ||||||||
|
Subroutine
jobRestart: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 124 | 0 | my ($self, $name) = @_; | |||||||||
| 125 | 0 | $name = $name . $self->Name; | |||||||||
| 126 | 0 | $self->_daem->jobEnd($name); | |||||||||
| 127 | 0 | $self->_daem->jobStart($name, $self->interval, @_); | |||||||||
| 128 | } | ||||||||||
| 129 | |||||||||||
| 130 | =item B<jobResume>I<($name)> | ||||||||||
| 131 | |||||||||||
| 132 | =cut | ||||||||||
| 133 | |||||||||||
| 134 | 0 | ▶ | sub jobResume { | ||||||||
|
Subroutine
jobResume: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 135 | 0 | my ($self, $name) = @_; | |||||||||
| 136 | 0 | $name = $name . $self->Name; | |||||||||
| 137 | 0 | $self->_daem->jobResume($name); | |||||||||
| 138 | } | ||||||||||
| 139 | |||||||||||
| 140 | =item B<jobStart>I<($name)> | ||||||||||
| 141 | |||||||||||
| 142 | =cut | ||||||||||
| 143 | |||||||||||
| 144 | 0 | ▶ | sub jobStart { | ||||||||
|
Subroutine
jobStart: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 145 | 0 | my $self = shift; | |||||||||
| 146 | 0 | my $name = shift; | |||||||||
| 147 | 0 | ▶ | croak 'Name not defined' unless defined $name; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 148 | 0 | $name = $name . $self->Name; | |||||||||
| 149 | 0 | $self->_daem->jobAdd($name, $self->interval, @_); | |||||||||
| 150 | } | ||||||||||
| 151 | |||||||||||
| 152 | 0 | ▶ | sub Unload { | ||||||||
|
Subroutine
Unload: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 153 | 0 | my $self = shift; | |||||||||
| 154 | 0 | for ($self->jobList) { $self->jobEnd($_) }; | |||||||||
| 155 | 0 | return $self->SUPER::Unload | |||||||||
| 156 | } | ||||||||||
| 157 | |||||||||||
| 158 | =back | ||||||||||
| 159 | |||||||||||
| 160 | =head1 AUTHOR | ||||||||||
| 161 | |||||||||||
| 162 | Hans Jeuken (hanje at cpan dot org) | ||||||||||
| 163 | |||||||||||
| 164 | =head1 BUGS | ||||||||||
| 165 | |||||||||||
| 166 | Unknown. If you find any, please contact the author. | ||||||||||
| 167 | |||||||||||
| 168 | =head1 SEE ALSO | ||||||||||
| 169 | |||||||||||
| 170 | =over 4 | ||||||||||
| 171 | |||||||||||
| 172 | =item L<Tk::AppWindow::BaseClasses::Plugin> | ||||||||||
| 173 | |||||||||||
| 174 | =item L<Tk::AppWindow> | ||||||||||
| 175 | |||||||||||
| 176 | =back | ||||||||||
| 177 | |||||||||||
| 178 | =cut | ||||||||||
| 179 | |||||||||||
| 180 | 1 | 1; | |||||||||
| 181 | |||||||||||
| 182 | |||||||||||
| 183 | |||||||||||
| 184 | |||||||||||
| 185 | |||||||||||
| 186 | |||||||||||
| 187 | |||||||||||
| 188 | |||||||||||
| 189 | |||||||||||
| 190 | |||||||||||
| 191 | |||||||||||
| 192 | |||||||||||