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 = 20181005; |
9
|
1
|
|
|
1
|
|
401
|
use v5.8.0; |
|
1
|
|
|
|
|
7
|
|
10
|
1
|
|
|
1
|
|
5
|
use warnings FATAL => qw(all); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
11
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
12
|
1
|
|
|
1
|
|
14
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
69
|
|
13
|
1
|
|
|
1
|
|
1213
|
use Data::Table::Text qw(:all); |
|
1
|
|
|
|
|
67344
|
|
|
1
|
|
|
|
|
942
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my @flipflops; # Flip::Flops encountered |
16
|
|
|
|
|
|
|
my $startProcess = $$; # Starting process |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub AUTOLOAD # Any method will do |
19
|
2
|
100
|
|
2
|
|
75
|
{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
|
|
837
|
{if ($startProcess eq $$) # Reset the flip flops once in the starting process |
25
|
1
|
50
|
|
|
|
4
|
{unless($?) # Clean run? |
26
|
1
|
|
|
|
|
3
|
{my $S = my $s = readFile($0); # Read source |
27
|
1
|
|
|
|
|
9638
|
for my $program(@flipflops) # Each flip flop |
28
|
1
|
|
|
|
|
3
|
{my $f = "$program(0)"; # Regular expression to set the switch to zero |
29
|
1
|
50
|
|
|
|
16
|
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
|
|
|
|
|
19
|
$s =~ s($F)($f)gs; # Reset switch |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
1
|
50
|
|
|
|
8
|
overWriteFile($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. The switch will |
73
|
|
|
|
|
|
|
only be reset if your program requests the reset and exits explicitly or |
74
|
|
|
|
|
|
|
implicitly with exit(0). |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
You can have as many such switches as desired. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
If your program L, then only the process in which Perl was started |
79
|
|
|
|
|
|
|
will update the Flip::Flop switches. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This capability will only be useful to you if you are using an editor that |
82
|
|
|
|
|
|
|
detects changes made independently to the file currently being edited. If you |
83
|
|
|
|
|
|
|
do use such an editor this technique is surprisingly useful for simplifying, |
84
|
|
|
|
|
|
|
standardizing, streamlining and supporting your edit/run cycle. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 Installation |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
This module is written in 100% Pure Perl and, thus, it is easy to read, use, |
89
|
|
|
|
|
|
|
modify and install. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Standard Module::Build process for building and installing modules: |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sudo cpan install Flip::Flop |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 Author |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
L |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
L |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 Copyright |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Copyright (c) 2016-2018 Philip R Brenan. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
This module is free software. It may be used, redistributed and/or modified |
106
|
|
|
|
|
|
|
under the same terms as Perl itself. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
END |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
# podDocumentation |