[otrs-cvs] otrs/Kernel/System YAML.pm, 1.3, 1.4 DynamicField.pm, 1.65, 1.66
"CVS commits notifications of OTRS.org" <[email protected]>
| Newsgroups | gmane.comp.otrs.cvs |
|---|---|
| Message-ID | <[email protected]> |
Comments:
Update of /home/cvs/otrs/Kernel/System
In directory lancelot:/tmp/cvs-serv9398/Kernel/System
Modified Files:
YAML.pm DynamicField.pm
Log Message:
Re-implemented Kernel::System::YAML as OOP.
Author: cr
Index: YAML.pm
===================================================================
RCS file: /home/cvs/otrs/Kernel/System/YAML.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -2 -u -d -r1.3 -r1.4
--- YAML.pm 16 Jan 2013 09:02:28 -0000 1.3
+++ YAML.pm 17 Jan 2013 03:39:21 -0000 1.4
@@ -18,5 +18,5 @@
use Encode qw();
-use vars qw($VERSION);
+use vars qw(@ISA $VERSION);
$VERSION = qw($Revision$) [1];
@@ -27,5 +27,5 @@
=head1 SYNOPSIS
-Call this module directly without instantiating.
+Functions for encoding perl data structures to YAML.
=over 4
@@ -33,6 +33,68 @@
=cut
+=item new()
+
+create a YAML object
+
+ use Kernel::Config;
+ use Kernel::System::Encode;
+ use Kernel::System::Log;
+ use Kernel::System::YAML;
+
+ my $ConfigObject = Kernel::Config->new();
+ my $EncodeObject = Kernel::System::Encode->new(
+ ConfigObject => $ConfigObject,
+ );
+ my $LogObject = Kernel::System::Log->new(
+ ConfigObject => $ConfigObject,
+ EncodeObject => $EncodeObject,
+ );
+
+ my $YAMLObject = Kernel::System::YAML->new(
+ ConfigObject => $ConfigObject,
+ EncodeObject => $EncodeObject,
+ LogObject => $LogObject,
+ );
+
+=cut
+
+sub new {
+ my ( $Type, %Param ) = @_;
+
+ # allocate new hash for object
+ my $Self = {};
+ bless( $Self, $Type );
+
+ # check needed objects
+ for my $Object (qw(ConfigObject EncodeObject LogObject)) {
+ $Self->{$Object} = $Param{$Object} || die "Got no $Object!";
+ }
+
+ return $Self;
+}
+
+=item Dump()
+
+Dump a perl data structure to a YAML string.
+
+ my $YAMLString = $YAMLObject->Dump(
+ Data => $Data,
+ );
+
+=cut
+
sub Dump {
- my $Result = YAML::Any::Dump(@_);
+ my ( $Self, %Param ) = @_;
+
+ # check for needed data
+ if ( !defined $Param{Data} ) {
+ $Self->{LogObject}->Log(
+ Priority => 'error',
+ Message => 'Need Data!',
+ );
+ return;
+ }
+
+ my $Result = YAML::Any::Dump( $Param{Data} ) || "--- ''\n";
# Make sure the resulting string has the UTF-8 flag.
@@ -42,11 +104,33 @@
}
+=item Load()
+
+Load a YAML string to a perl data structure.
+
+ my $PerlStructureScalar = $YAMLObject->Load(
+ Data => $YAMLString,
+ );
+
+=cut
+
sub Load {
- my $Result = eval {
- if ( Encode::is_utf8( $_[0] ) ) {
- Encode::_utf8_off( $_[0] );
- }
- YAML::Any::Load(@_);
- };
+ my ( $Self, %Param ) = @_;
+
+ # check for needed data
+ return if !defined $Param{Data};
+
+ if ( Encode::is_utf8( $Param{Data} ) ) {
+ Encode::_utf8_off( $Param{Data} );
+ }
+
+ my $Result;
+
+ if ( !eval { $Result = YAML::Any::Load( $Param{Data} ) } ) {
+ $Self->{LogObject}->Log(
+ Priority => 'error',
+ Message => 'Loading the YAML string failed: ' . $@,
+ );
+ return;
+ }
_AddUTF8Flag( \$Result ) if defined $Result;
Author: cr
Index: DynamicField.pm
===================================================================
RCS file: /home/cvs/otrs/Kernel/System/DynamicField.pm,v
retrieving revision 1.65
retrieving revision 1.66
diff -2 -u -d -r1.65 -r1.66
--- DynamicField.pm 15 Jan 2013 17:43:26 -0000 1.65
+++ DynamicField.pm 17 Jan 2013 03:39:21 -0000 1.66
@@ -95,4 +95,5 @@
$Self->{CacheObject} = Kernel::System::Cache->new( %{$Self} );
$Self->{ValidObject} = Kernel::System::Valid->new( %{$Self} );
+ $Self->{YAMLObject} = Kernel::System::YAML->new( %{$Self} );
# get the cache TTL (in seconds)
@@ -185,5 +186,5 @@
# dump config as string
- my $Config = Kernel::System::YAML::Dump( $Param{Config} );
+ my $Config = $Self->{YAMLObject}->Dump( Data => $Param{Config} );
# Make sure the resulting string has the UTF-8 flag. YAML only sets it if
@@ -305,5 +306,5 @@
my %Data;
while ( my @Data = $Self->{DBObject}->FetchrowArray() ) {
- my $Config = Kernel::System::YAML::Load( $Data[7] ) || {};
+ my $Config = $Self->{YAMLObject}->Load( Data => $Data[7] ) || {};
%Data = (
@@ -373,5 +374,5 @@
# dump config as string
- my $Config = Kernel::System::YAML::Dump( $Param{Config} );
+ my $Config = $Self->{YAMLObject}->Dump( Data => $Param{Config} );
# Make sure the resulting string has the UTF-8 flag. YAML only sets it if
---------------------------------------------------------------------
OTRS mailing list: cvs-log - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/cvs-log
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/cvs-log