line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Goo::Thing::pm::Perl5Compiler; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
############################################################################### |
6
|
|
|
|
|
|
|
# Nigel Hamilton |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# Copyright Nigel Hamilton 2005 |
9
|
|
|
|
|
|
|
# All Rights Reserved |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# Author: Nigel Hamilton |
12
|
|
|
|
|
|
|
# Filename: Goo::Thing::pm::Perl5Compiler.pm |
13
|
|
|
|
|
|
|
# Description: Compile a Perl program |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# Date Change |
16
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------- |
17
|
|
|
|
|
|
|
# 01/08/05 Factored out of ProgramEditor as part of the new Goo |
18
|
|
|
|
|
|
|
# 30/08/2005 Added method: processError |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
############################################################################## |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
25
|
|
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
1
|
|
5
|
use Goo::Object; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
25
|
1
|
|
|
1
|
|
6
|
use Goo::Prompter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
1
|
|
4
|
use base qw(Goo::Object); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
366
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# constant! |
30
|
|
|
|
|
|
|
my $last_error_file = "/tmp/last-goo-error.txt"; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
############################################################################### |
34
|
|
|
|
|
|
|
# |
35
|
|
|
|
|
|
|
# run - keep adding a thing to the program |
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
############################################################################### |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub run { |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
0
|
1
|
|
my ($this, $thing) = @_; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $filename = $thing->get_full_path(); |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
Goo::Prompter::say("Compiling ..."); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# remove any previous erros |
48
|
0
|
|
|
|
|
|
unlink($last_error_file); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# redirect STDERR to STDOUT |
51
|
0
|
|
|
|
|
|
my $results = `/usr/bin/perl -I$ENV{HOME}/.goo -c $filename 2 &> $last_error_file`; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# do we have any errors? |
54
|
0
|
0
|
|
|
|
|
if (-e $last_error_file) { |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# oops - compilation included an error - lets jump to it |
57
|
0
|
|
|
|
|
|
process_error($thing); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
Goo::Prompter::notify("Finished compiling.\nPress a key to continue."); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
############################################################################### |
67
|
|
|
|
|
|
|
# |
68
|
|
|
|
|
|
|
# process_error - enable the user to jump to the last error |
69
|
|
|
|
|
|
|
# |
70
|
|
|
|
|
|
|
############################################################################### |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub process_error { |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
0
|
1
|
|
my ($thing) = @_; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $error_report = Goo::FileUtilities::slurp($last_error_file); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# show the errors! |
79
|
0
|
|
|
|
|
|
print $error_report; |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
if ($error_report =~ m/.*line\s+(\d+)/s) { |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $error_on_line = $1; |
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
if (Goo::Prompter::confirm("Jump to error on line $error_on_line?")) { |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# there was an error - jump to the line |
88
|
0
|
|
|
|
|
|
$thing->do_action("J", $error_on_line); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 NAME |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Goo::Thing::pm::Perl5Compiler - Compile a Perl program |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 SYNOPSIS |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
use Goo::Thing::pm::Perl5Compiler; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 DESCRIPTION |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 METHODS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=over |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item run |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
call /usr/bin/perl -c to compile the code. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item process_error |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
catch any error so the user can jump to the last error |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=back |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 AUTHOR |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Nigel Hamilton <nigel@trexy.com> |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 SEE ALSO |