projects
/
kivitendo-erp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
JS-Menü-Einträge schmaler rendern
[kivitendo-erp.git]
/
SL
/
SessionFile.pm
diff --git
a/SL/SessionFile.pm
b/SL/SessionFile.pm
index
12f4984
..
6f04041
100644
(file)
--- a/
SL/SessionFile.pm
+++ b/
SL/SessionFile.pm
@@
-5,7
+5,7
@@
use strict;
use parent qw(Rose::Object);
use Carp;
use parent qw(Rose::Object);
use Carp;
-use File::Path qw(m
ake_path remove_
tree);
+use File::Path qw(m
kpath rm
tree);
use English qw(-no_match_vars);
use IO::File;
use POSIX qw(strftime);
use English qw(-no_match_vars);
use IO::File;
use POSIX qw(strftime);
@@
-16,7
+16,7
@@
use Rose::Object::MakeMethods::Generic
);
sub new {
);
sub new {
- my ($class, $file_name,
$mode
) = @_;
+ my ($class, $file_name,
%params
) = @_;
my $self = $class->SUPER::new;
my $self = $class->SUPER::new;
@@
-24,12
+24,27
@@
sub new {
$file_name =~ s:.*/::g;
$file_name = "${path}/${file_name}";
$file_name =~ s:.*/::g;
$file_name = "${path}/${file_name}";
- $self->fh(IO::File->new($file_name, $mode)) if $mode;
$self->file_name($file_name);
$self->file_name($file_name);
+ if ($params{mode}) {
+ my $mode = $params{mode};
+
+ if ($params{encoding}) {
+ $params{encoding} =~ s/[^a-z0-9\-]//gi;
+ $mode .= ':encoding(' . $params{encoding} . ')';
+ }
+
+ $self->fh(IO::File->new($file_name, $mode));
+ }
+
return $self;
}
return $self;
}
+sub open {
+ my ($self, $mode) = @_;
+ return $self->fh(IO::File->new($self->file_name, $mode));
+}
+
sub exists {
my ($self) = @_;
return -f $self->file_name;
sub exists {
my ($self) = @_;
return -f $self->file_name;
@@
-56,7
+71,7
@@
sub get_path {
sub prepare_path {
my $path = get_path();
return $path if -d $path;
sub prepare_path {
my $path = get_path();
return $path if -d $path;
- m
ake_
path $path;
+ m
k
path $path;
die "Creating ${path} failed" unless -d $path;
return $path;
}
die "Creating ${path} failed" unless -d $path;
return $path;
}
@@
-65,7
+80,7
@@
sub destroy_session {
my ($class, $session_id) = @_;
$session_id =~ s/[^a-z0-9]//gi;
my ($class, $session_id) = @_;
$session_id =~ s/[^a-z0-9]//gi;
- r
emove_
tree "users/session_files/$session_id" if $session_id;
+ r
m
tree "users/session_files/$session_id" if $session_id;
}
1;
}
1;
@@
-85,7
+100,7
@@
destroyed or expires
use SL::SessionFile;
# Create a session file named "customer.csv" (relative names only)
use SL::SessionFile;
# Create a session file named "customer.csv" (relative names only)
- my $sfile = SL::SessionFile->new(
"customer.csv", "w"
);
+ my $sfile = SL::SessionFile->new(
'customer.csv', mode => 'w'
);
$sfile->fh->print("col1;col2;col3\n" .
"value1;value2;value3\n");
$sfile->fh->close;
$sfile->fh->print("col1;col2;col3\n" .
"value1;value2;value3\n");
$sfile->fh->close;
@@
-108,13
+123,16
@@
C<users/session_files/SESSIONID>.
=over 4
=over 4
-=item C<new $file_name, [
$mode
]>
+=item C<new $file_name, [
%params
]>
Create a new instance. C<$file_name> is a relative file name (path
components are stripped) to the session-specific temporary directory.
Create a new instance. C<$file_name> is a relative file name (path
components are stripped) to the session-specific temporary directory.
-If C<$mode> is given then try to open the file as an instance of
-C<IO::File>. C<$mode> is passed through to C<IO::File::new>.
+If C<$params{mode}> is given then try to open the file as an instance
+of C<IO::File>. C<${mode}> is passed through to C<IO::File::new>.
+
+If C<$params{encoding}> is given then the file is opened with the
+appropriate encoding layer.
=item C<fh>
=item C<fh>
@@
-126,6
+144,10
@@
Returns the full relative file name associated with this instance. If
it has been created for "customer.csv" then the value returned might
be C<users/session_files/e8789b98721347/customer.csv>.
it has been created for "customer.csv" then the value returned might
be C<users/session_files/e8789b98721347/customer.csv>.
+=item C<open, %params]>
+
+Opens the file_name given at creation with the given parameters.
+
=item C<exists>
Returns trueish if the file exists.
=item C<exists>
Returns trueish if the file exists.