From ab9162acadd688f4020475b15fbbcd30549e2e33 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 2 May 2011 17:26:20 +0200 Subject: [PATCH] =?utf8?q?M=C3=B6glichkeit,=20das=20Encoding=20anzugeben;?= =?utf8?q?=20'mode'-Paramter=20ist=20nun=20">"=20oder=20"<"?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Conflicts: SL/SessionFile.pm --- SL/SessionFile.pm | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/SL/SessionFile.pm b/SL/SessionFile.pm index b9a5b7697..dbed4154b 100644 --- a/SL/SessionFile.pm +++ b/SL/SessionFile.pm @@ -16,7 +16,7 @@ use Rose::Object::MakeMethods::Generic ); sub new { - my ($class, $file_name, $mode) = @_; + my ($class, $file_name, %params) = @_; my $self = $class->SUPER::new; @@ -24,7 +24,17 @@ sub new { $file_name =~ s:.*/::g; $file_name = "${path}/${file_name}"; - $self->fh(IO::File->new($file_name, $mode)) if $mode; + 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)); + } + $self->file_name($file_name); return $self; @@ -108,13 +118,16 @@ C. =over 4 -=item C +=item C 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. C<$mode> is passed through to C. +If C<$params{mode}> is given then try to open the file as an instance +of C. C<${mode}> is passed through to C. + +If C<$params{encoding}> is given then the file is opened with the +appropriate encoding layer. =item C -- 2.20.1