line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# shell::script Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Shell::Script; |
7
|
1
|
|
|
1
|
|
627
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use base qw(Metabrik); |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
544
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(scripting) ], |
16
|
|
|
|
|
|
|
attributes => { |
17
|
|
|
|
|
|
|
input => [ qw(file) ], |
18
|
|
|
|
|
|
|
}, |
19
|
|
|
|
|
|
|
commands => { |
20
|
|
|
|
|
|
|
load => [ qw(input|OPTIONAL) ], |
21
|
|
|
|
|
|
|
execute => [ qw($line_list) ], |
22
|
|
|
|
|
|
|
load_and_execute => [ qw(input|OPTIONAL) ], |
23
|
|
|
|
|
|
|
}, |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub load { |
28
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
29
|
0
|
|
|
|
|
|
my ($input) = @_; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
0
|
|
|
|
$input ||= $self->input; |
32
|
0
|
0
|
|
|
|
|
$self->brik_help_run_file_not_found('load', $input) or return; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my @lines = (); |
35
|
0
|
0
|
|
|
|
|
open(my $in, '<', $input) |
36
|
|
|
|
|
|
|
or return $self->log->error("load: can't open file [$input]: $!"); |
37
|
0
|
|
|
|
|
|
while (defined(my $line = <$in>)) { |
38
|
0
|
|
|
|
|
|
chomp($line); |
39
|
0
|
0
|
|
|
|
|
next if $line =~ /^\s*$/; # Skip blank lines |
40
|
0
|
0
|
|
|
|
|
next if $line =~ /^\s*#/; # Skip comments |
41
|
0
|
|
|
|
|
|
$line =~ s/^(.*)#.*$/$1/; # Strip comments at end of line |
42
|
0
|
|
|
|
|
|
push @lines, "$line "; # Add a trailing slash in case of a multiline |
43
|
|
|
|
|
|
|
# So when joining them, there is no unwanted concatenation |
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
|
|
|
close($in); |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
return \@lines; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub execute { |
51
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
52
|
0
|
|
|
|
|
|
my ($lines) = @_; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
if (! defined($self->shell)) { |
55
|
0
|
|
|
|
|
|
return $self->log->error("execute: no core::shell Brik"); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('execute', $lines) or return; |
59
|
0
|
0
|
|
|
|
|
$self->brik_help_run_invalid_arg('execute', $lines, 'ARRAY') or return; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $shell = $self->shell; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$shell->cmdloop($lines); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return 1; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub load_and_execute { |
69
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
70
|
0
|
|
|
|
|
|
my ($input) = @_; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
0
|
|
|
|
$input ||= $self->input; |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
my $lines = $self->load($input) or return; |
75
|
0
|
|
|
|
|
|
return $self->execute($lines); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |