| 1 | package Sys::RunAlways; | ||||||||||
| 2 | |||||||||||
| 3 | # version info | ||||||||||
| 4 | 5 | $VERSION= '0.08'; | |||||||||
| 5 | |||||||||||
| 6 | # be as strict and verbose as possible | ||||||||||
| 7 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | # make sure we know how to lock | ||||||||||
| 11 | 5 | ▶ | use Fcntl ':flock'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | # process local storage | ||||||||||
| 14 | 5 | my $silent; | |||||||||
| 15 | |||||||||||
| 16 | # satisfy -require- | ||||||||||
| 17 | 5 | 1; | |||||||||
| 18 | |||||||||||
| 19 | #------------------------------------------------------------------------------- | ||||||||||
| 20 | # | ||||||||||
| 21 | # Standard Perl functionality | ||||||||||
| 22 | # | ||||||||||
| 23 | #------------------------------------------------------------------------------- | ||||||||||
| 24 | # import | ||||||||||
| 25 | # | ||||||||||
| 26 | # IN: 1 class (not used) | ||||||||||
| 27 | # 2 .. N options (default: none) | ||||||||||
| 28 | |||||||||||
| 29 | 5 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=2 SCAR=7.4
| |||||||||||
| 30 | 5 | my ( undef, %args )= @_; | |||||||||
| 31 | |||||||||||
| 32 | # obtain parameters | ||||||||||
| 33 | 5 | $silent= delete $args{silent}; | |||||||||
| 34 | |||||||||||
| 35 | # sanity check | ||||||||||
| 36 | 5 | ▶ | if ( my @huh= sort keys %args ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | die "Don't know what to do with: @huh"; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 5 | return; | |||||||||
| 41 | } #import | ||||||||||
| 42 | |||||||||||
| 43 | #------------------------------------------------------------------------------- | ||||||||||
| 44 | |||||||||||
| 45 | 5 | ▶ | INIT { | ||||||||
|
Subroutine
INIT: called CC=4 SCAR=13.9
| |||||||||||
| 46 | # no warnings here | ||||||||||
| 47 | 5 | ▶ | no warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 48 | |||||||||||
| 49 | # no data handle, we're screwed | ||||||||||
| 50 | 5 | ▶ | print( STDERR "Add __END__ to end of script '$0' to be able use the features of Sys::RunAlways\n" ),exit 2 | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | if tell( *main::DATA ) == -1; | ||||||||||
| 52 | |||||||||||
| 53 | # we're still running | ||||||||||
| 54 | 4 | ▶ | exit 0 if !flock main::DATA,LOCK_EX | LOCK_NB; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | |||||||||||
| 56 | # tell the world if necessary | ||||||||||
| 57 | 2 | ▶ | printf STDERR "'%s' has been started at %s\n", $0, scalar time | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | if !$silent; | ||||||||||
| 59 | } #INIT | ||||||||||
| 60 | |||||||||||
| 61 | #------------------------------------------------------------------------------- | ||||||||||
| 62 | |||||||||||
| 63 | __END__ | ||||||||||