-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathParserTst.pm
105 lines (89 loc) · 1.83 KB
/
ParserTst.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package ParserTst;
#
# To use this Class :
# use ParserTst;
# my $parse = ParserTst->new("pathname.tst");
# $parse->getCmd(); to get a command.
# $parse->getStdin(); to get a stdin.
# $parse->getStdout(); to get a stdout.
# $parse->getStderr(); to get a stderr.
# $parse->getRet(); to get a return value.
# $parse->getRef(); to get a reference command.
#
# --------------------------------------
sub new
{
my ($class, $filepath) = @_;
my $self = { };
$self->{FileStr} = fileToStr($filepath);
$self->{cmd} = getElement($self->{FileStr}, "cmd");
$self->{stdout} = getElement($self->{FileStr}, "stdout");
$self->{stdin} = getElement($self->{FileStr}, "stdin");
$self->{stderr} = getElement($self->{FileStr}, "stderr");
$self->{ret} = getElement($self->{FileStr}, "ret");
$self->{ref} = getElement($self->{FileStr}, "ref");
bless($self, $class);
return ($self);
}
# --------------------------------------
sub getCmd
{
my $self = shift;
return $self->{cmd};
}
sub getStdout
{
my $self = shift;
return $self->{stdout};
}
sub getStdin
{
my $self = shift;
return $self->{stdin};
}
sub getStderr
{
my $self = shift;
return $self->{stderr};
}
sub getRet
{
my $self = shift;
return $self->{ret};
}
sub getRef
{
my $self = shift;
return $self->{ref};
}
# utils
# --------------------------------------
sub fileToStr
{
my ($path) = @_;
my $str = "";
if (!(-e $path)) {
print "Le fichier $path n'existe pas\n";
return (undef);
}
open FD, $path;
my @lines = <FD>;
foreach my $l (@lines) {
$str .= $l;
}
close FD;
return ($str);
}
sub getElement
{
my ($fileStr, $motif) = @_;
my $str = "";
if (!$fileStr){
return (undef);
}
if ($fileStr =~ /<$motif>\n((.|\n)*)<\/$motif>/){
$str = $1;
}
return $str;
}
1;