$VERSION
=
'0.02'
;
@ISA
=
qw( Exporter DynaLoader )
;
@EXPORT
=
qw()
;
$ErrorNum
= 0;
$ErrorText
=
""
;
sub
new
{
my
(
$self
,
$Pipe
);
my
(
$Type
,
$Name
,
$Time
) =
@_
;
if
(!
$Time
){
$Time
= DEFAULT_WAIT_TIME;
}
$Pipe
= PipeCreate(
$Name
,
$Time
);
if
(
$Pipe
){
$self
=
bless
{};
$self
->{
'Pipe'
} =
$Pipe
;
}
else
{
(
$ErrorNum
,
$ErrorText
) = PipeError();
return
undef
;
}
$self
;
}
sub
Write{
my
(
$self
,
$Data
) =
@_
;
$Data
= PipeWrite(
$self
->{
'Pipe'
},
$Data
);
return
$Data
;
}
sub
Read{
my
(
$self
) =
@_
;
my
(
$Data
);
$Data
= PipeRead(
$self
->{
'Pipe'
});
return
$Data
;
}
sub
Error{
my
(
$self
) =
@_
;
my
(
$MyError
,
$MyErrorText
,
$Temp
);
if
(!
ref
(
$self
)){
undef
$Temp
;
}
else
{
$Temp
=
$self
->{
'Pipe'
};
}
(
$MyError
,
$MyErrorText
) = PipeError(
$Temp
);
return
wantarray
? (
$MyError
,
$MyErrorText
):
"[$MyError] \"$MyErrorText\""
;
}
sub
Close{
my
(
$self
) =
shift
;
PipeClose(
$self
->{
'Pipe'
});
}
sub
Connect{
my
(
$self
) =
@_
;
my
(
$Result
);
$Result
= PipeConnect(
$self
->{
'Pipe'
});
return
$Result
;
}
sub
Disconnect{
my
(
$self
,
$iPurge
) =
@_
;
my
(
$Result
);
if
(!
$iPurge
){
$iPurge
= 1;
}
$Result
= PipeDisconnect(
$self
->{
'Pipe'
},
$iPurge
);
return
$Result
;
}
sub
BufferSize{
my
(
$self
) =
@_
;
my
(
$Result
) = PipeBufferSize(
$self
->{
'Pipe'
});
return
$Result
;
}
sub
ResizeBuffer{
my
(
$self
,
$Size
) =
@_
;
my
(
$Result
) = PipeResizeBuffer(
$self
->{
'Pipe'
},
$Size
);
return
$Result
;
}
sub
DESTROY
{
my
(
$self
) =
shift
;
Close(
$self
);
}
sub
Credit{
my
(
$Name
,
$Version
,
$Date
,
$Author
,
$CompileDate
,
$CompileTime
,
$Credits
) = Win32::Pipe::Info();
my
(
$Out
,
$iWidth
);
$iWidth
= 60;
$Out
.=
"\n"
;
$Out
.=
" +"
.
"="
x (
$iWidth
).
"+\n"
;
$Out
.=
" |"
. Center(
""
,
$iWidth
).
"|\n"
;
$Out
.=
" |"
. Center(
""
,
$iWidth
).
"|\n"
;
$Out
.=
" |"
. Center(
"$Name"
,
$iWidth
).
"|\n"
;
$Out
.=
" |"
. Center(
"-"
x
length
(
"$Name"
),
$iWidth
).
"|\n"
;
$Out
.=
" |"
. Center(
""
,
$iWidth
).
"|\n"
;
$Out
.=
" |"
. Center(
"Version $Version ($Date)"
,
$iWidth
).
"|\n"
;
$Out
.=
" |"
. Center(
"by $Author"
,
$iWidth
).
"|\n"
;
$Out
.=
" |"
. Center(
"Compiled on $CompileDate at $CompileTime."
,
$iWidth
).
"|\n"
;
$Out
.=
" |"
. Center(
""
,
$iWidth
).
"|\n"
;
$Out
.=
" |"
. Center(
"Credits:"
,
$iWidth
).
"|\n"
;
$Out
.=
" |"
. Center((
"-"
x
length
(
"Credits:"
)),
$iWidth
).
"|\n"
;
foreach
$Temp
(
split
(
"\n"
,
$Credits
)){
$Out
.=
" |"
. Center(
"$Temp"
,
$iWidth
).
"|\n"
;
}
$Out
.=
" |"
. Center(
""
,
$iWidth
).
"|\n"
;
$Out
.=
" +"
.
"="
x (
$iWidth
).
"+\n"
;
return
$Out
;
}
sub
Center{
local
(
$Temp
,
$Width
) =
@_
;
local
(
$Len
) = (
$Width
-
length
(
$Temp
)) / 2;
return
" "
x
int
(
$Len
) .
$Temp
.
" "
x (
int
(
$Len
) + ((
$Len
!=
int
(
$Len
))? 1:0));
}
sub
AUTOLOAD {
my
(
$constname
);
(
$constname
=
$AUTOLOAD
) =~ s/.*:://;
$!=0;
$val
= constant(
$constname
,
@_
?
$_
[0] : 0);
if
($! != 0) {
if
($! =~ /Invalid/) {
$AutoLoader::AUTOLOAD
=
$AUTOLOAD
;
goto
&AutoLoader::AUTOLOAD
;
}
else
{
$pack
= 0;
(
$pack
,
$file
,
$line
) =
caller
;
print
"Your vendor has not defined Win32::Pipe macro $constname, used in $file at line $line."
;
}
}
eval
"sub $AUTOLOAD { $val }"
;
goto
&$AUTOLOAD
;
}
bootstrap Win32::Pipe;
1;