our
$VERSION
=
'0.3'
;
sub
size {
shift
->{size}};
sub
name {
shift
->{name}};
sub
path {
shift
->{path}};
sub
fh {
my
$self
=
shift
;
unless
(
$self
->{fh}){
open
(
$self
->{fh},
'<'
,
$self
->{path}) or
die
'Can`t open tmp file '
.
$self
->{path};
binmode
$self
->{fh};
}
return
$self
->{fh};
}
sub
save {
my
(
$self
,
$dest
) =
@_
;
close
delete
$self
->{fh}
if
$self
->{fh};
if
(
$self
->{moved}){
copy(
$self
->{path},
$dest
) or
die
'Can`t save tmp file '
.
$self
->{path}.
' to '
.
$dest
;
}
else
{
move(
$self
->{path},
$dest
) or
die
'Can`t save tmp file '
.
$self
->{path}.
' to '
.
$dest
;
$self
->{path} =
$dest
;
$self
->{moved} = 1;
}
}
sub
del {
my
$self
=
shift
;
close
$self
->{fh}
if
$self
->{fh};
unlink
$self
->{path}
unless
$self
->{moved};
}
*DESTROY
= \
&del
;
1;