line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Goo::Thing::pm::ExecDocManager; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
############################################################################### |
4
|
|
|
|
|
|
|
# Nigel Hamilton |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Copyright Nigel Hamilton 2005 |
7
|
|
|
|
|
|
|
# All Rights Reserved |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# Author: Nigel Hamilton |
10
|
|
|
|
|
|
|
# Filename: Goo::Thing::pm::ExecDocManager.pm |
11
|
|
|
|
|
|
|
# Description: Process ThereDocs embedded in Things |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# Date Change |
14
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
15
|
|
|
|
|
|
|
# 16/08/2005 Auto generated file |
16
|
|
|
|
|
|
|
# 16/08/2005 Needed a way to jump from Here to There |
17
|
|
|
|
|
|
|
# |
18
|
|
|
|
|
|
|
############################################################################### |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
6
|
use Goo::Prompter; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
20
|
|
23
|
1
|
|
|
1
|
|
7
|
use Goo::FileUtilities; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
251
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# an execdoc is a small snippet of code you want to execute on it's own |
26
|
|
|
|
|
|
|
# in the current program |
27
|
|
|
|
|
|
|
my $exec_doc_start = qr/!!>/; # execute code here |
28
|
|
|
|
|
|
|
my $exec_doc_end = qr/<!!/; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
############################################################################### |
32
|
|
|
|
|
|
|
# |
33
|
|
|
|
|
|
|
# process - given a string, look for there_docs and then do things if you find one! |
34
|
|
|
|
|
|
|
# |
35
|
|
|
|
|
|
|
############################################################################### |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub process { |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
0
|
1
|
|
my ($thing) = @_; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# get the contents afresh |
42
|
0
|
|
|
|
|
|
my $contents = Goo::FileUtilities::getFileAsString($thing->get_full_path()); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# bail out if no ThereDoc is present |
45
|
0
|
0
|
|
|
|
|
return unless ($contents =~ /$exec_doc_start/); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# match the string the ThereDoc is targetting |
48
|
0
|
|
|
|
|
|
$contents =~ /$exec_doc_start(.*)$exec_doc_end/ms; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $target = $1; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
eval($1); |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
if ($@) { |
55
|
0
|
|
|
|
|
|
Goo::Prompter::notify("Error occurred: $@"); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
Goo::Prompter::notify("Execute code complete."); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# go back to editing |
61
|
0
|
|
|
|
|
|
$thing->do_action("J", $exec_doc_start); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 NAME |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Goo::Thing::pm::ExecDocManager - Like ThereDocs except they execute inline |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 SYNOPSIS |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
use Goo::Thing::pm::ExecDocManager; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 DESCRIPTION |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This is an experimental idea. It means you can execute a one-liner while you're coding. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 METHODS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=over |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item process |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Given a string, look for an ExecDoc then execute the contents. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=back |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 AUTHOR |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Nigel Hamilton <nigel@trexy.com> |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 SEE ALSO |
97
|
|
|
|
|
|
|
|