$VERSION
= 0.045;
sub
new {
my
$class
=
ref
$_
[0] ?
ref
shift
:
shift
;
my
$self
=
bless
{
@_
},
$class
;
$self
->{Source} =
"run3.out"
unless
defined
$self
->{Source} &&
length
$self
->{Source};
my
$source
=
$self
->{Source};
if
(
ref
$source
eq
"GLOB"
|| UNIVERSAL::isa(
$source
,
"IO::Handle"
) ) {
$self
->{FH} =
$source
;
}
elsif
(
$source
eq
"-"
) {
$self
->{FH} = \
*STDIN
;
}
else
{
open
PROFILE,
"<$self->{Source}"
or
die
"$!: $self->{Source}\n"
;
$self
->{FH} =
*PROFILE
{IO};
}
return
$self
;
}
sub
set_handler {
$_
[0]->{Handler} =
$_
[1] }
sub
get_handler {
$_
[0]->{Handler} }
sub
read
{
my
$self
=
shift
;
my
$fh
=
$self
->{FH};
my
@ln
=
split
/ /, <
$fh
>;
return
0
unless
@ln
;
return
1
unless
$self
->{Handler};
chomp
$ln
[-1];
return
1
if
@ln
== 1 && !
length
$ln
[0] || 0 ==
index
$ln
[0],
"#"
;
if
(
$ln
[0] eq
"\\app_call"
) {
shift
@ln
;
my
@times
=
split
/,/,
pop
@ln
;
$self
->{Handler}->app_call(
[
map
{
s/\\\\/\\/g;
s/\\_/ /g;
$_
;
}
@ln
],
@times
);
}
elsif
(
$ln
[0] eq
"\\app_exit"
) {
shift
@ln
;
$self
->{Handler}->app_exit(
pop
@ln
,
@ln
);
}
else
{
my
@times
=
split
/,/,
pop
@ln
;
$self
->{Handler}->run_exit(
[
map
{
s/\\\\/\\/g;
s/\\_/ /g;
$_
;
}
@ln
],
@times
);
}
return
1;
}
sub
read_all {
my
$self
=
shift
;
1
while
$self
->
read
;
return
1;
}
1;