| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
2
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
3
|
|
|
|
|
|
|
# Set a switch in your script to zero after a run with the switch set to one. |
|
4
|
|
|
|
|
|
|
# Philip R Brenan at gmail dot com, Appa Apps Ltd Inc, 2016-2017 |
|
5
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Flip::Flop; |
|
8
|
|
|
|
|
|
|
our $VERSION = 20180726; |
|
9
|
1
|
|
|
1
|
|
470
|
use v5.8.0; |
|
|
1
|
|
|
|
|
9
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use warnings FATAL => qw(all); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
27
|
|
|
11
|
1
|
|
|
1
|
|
3
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
23
|
|
|
12
|
1
|
|
|
1
|
|
10
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
81
|
|
|
13
|
1
|
|
|
1
|
|
890
|
use Data::Table::Text qw(:all); |
|
|
1
|
|
|
|
|
77893
|
|
|
|
1
|
|
|
|
|
860
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my @flipflops; # Flip::Flops encountered |
|
16
|
|
|
|
|
|
|
my $startProcess = $$; # Starting process |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub AUTOLOAD # Any method will do |
|
19
|
2
|
100
|
|
2
|
|
85
|
{push @flipflops, $Flip::Flop::AUTOLOAD unless @_; # No parameters: flop switch, with parameters: flip switch to $[0] |
|
20
|
2
|
|
|
|
|
5
|
$_[0] |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
END |
|
24
|
1
|
50
|
|
1
|
|
960
|
{if ($startProcess eq $$) # Reset the flip flops once in the starting process |
|
25
|
1
|
50
|
|
|
|
3
|
{unless($?) # Clean run? |
|
26
|
1
|
|
|
|
|
6
|
{my $S = my $s = readFile($0); # Read source |
|
27
|
1
|
|
|
|
|
10707
|
for my $program(@flipflops) # Each flip flop |
|
28
|
1
|
|
|
|
|
4
|
{my $f = "$program(0)"; # Regular expression to set the switch to zero |
|
29
|
1
|
50
|
|
|
|
20
|
if ($s !~ m/$f/s) # Reset the switch if it is not already zero |
|
30
|
1
|
|
|
|
|
4
|
{my $F = "$program\\(\\d+\\)"; # Regular expression to find the switches |
|
31
|
1
|
|
|
|
|
31
|
$s =~ s($F)($f)gs; # Reset switch |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
} |
|
34
|
1
|
50
|
|
|
|
25
|
writeFile($0, $s) if $s ne $S; # Update source file if any switches were reset |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# podDocumentation |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=pod |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=encoding utf-8 |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 Name |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Flip::Flop - Set a switch in your script to zero after a run with the switch |
|
48
|
|
|
|
|
|
|
set to one. |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 Synopsis |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Some where near the top of your program you might have some variables |
|
53
|
|
|
|
|
|
|
(illustrated below by B) that select the actions the code is to |
|
54
|
|
|
|
|
|
|
perform on the next run from your IDE: |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $doUpload = Flip::Flop::uploadToCloud(1); |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
... |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
if ($doUpload) |
|
61
|
|
|
|
|
|
|
{... |
|
62
|
|
|
|
|
|
|
Flip::Flop::uploadToCloud(); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
If the upload succeeds, your program source code will be modified to read: |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $doUpload = Flip::Flop::uploadToCloud(0); |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
so that the next time you run your program from your IDE this lengthy operation |
|
70
|
|
|
|
|
|
|
will not be performed unless you explicitly re-request it. |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
If the run does not succeed the switch will be left unchanged. |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
You can have as many such switches as desired. |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
If your program L, then only the process in which Perl was started |
|
77
|
|
|
|
|
|
|
will update the Flip::Flop switches. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 Installation |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This module is written in 100% Pure Perl and, thus, it is easy to read, use, |
|
82
|
|
|
|
|
|
|
modify and install. |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Standard Module::Build process for building and installing modules: |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sudo cpan install Flip::Flop |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 Author |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
L |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
L |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 Copyright |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Copyright (c) 2016-2018 Philip R Brenan. |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This module is free software. It may be used, redistributed and/or modified |
|
99
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
END |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
|
106
|
|
|
|
|
|
|
# podDocumentation |