[Rt-commit] r5469 - rt/branches/3.7-EXPERIMENTAL-RTIR-2.0/lib/RT

ruz at bestpractical.com ruz at bestpractical.com
Mon Jun 26 19:12:49 EDT 2006


Author: ruz
Date: Mon Jun 26 19:12:48 2006
New Revision: 5469

Modified:
   rt/branches/3.7-EXPERIMENTAL-RTIR-2.0/lib/RT/Config.pm

Log:
* return old value on Set, so we could write:
   my @old_val = RT->Config->Set( Option => @tmp_val );
   ...
   RT->Config->Set( Option => @old_val );


Modified: rt/branches/3.7-EXPERIMENTAL-RTIR-2.0/lib/RT/Config.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-RTIR-2.0/lib/RT/Config.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL-RTIR-2.0/lib/RT/Config.pm	Mon Jun 26 19:12:48 2006
@@ -259,17 +259,8 @@
 
 =cut
 
-sub Get
-{
-    my $self = shift;
-    my $name = shift;
-    my $user = shift;
-    unless ( exists $OPTIONS{ $name } ) {
-        # if don't know anything about option
-        # return empty list, but undef in scalar
-        # context
-        return wantarray? (): undef;
-    }
+sub Get {
+    my ($self, $name, $user) = @_;
 
     my $res;
     if ( $user && $META{ $name }->{'Overridable'} ) {
@@ -278,34 +269,25 @@
         $res = $prefs->{ $name } if $prefs;
     }
     $res = $OPTIONS{ $name } unless defined $res;
-    return $res unless wantarray;
-
-    my $type = $META{ $name }->{'Type'} || 'SCALAR';
-    if( $type eq 'ARRAY' ) {
-        return @{ $res };
-    } elsif( $type eq 'HASH' ) {
-        return %{ $res };
-    }
-    return $res;
+    return $self->_ReturnValue($res, $META{ $name }->{'Type'} || 'SCALAR');
 }
 
 =head2 Set
 
 Takes two arguments: name of the option and new value.
-Set option's value to new value.
+Set option's value to new value. Returns old value.
 
 =cut
 
-sub Set
-{
-    my $self = shift;
-    my $name = shift;
-
-    my $type = $META{$name}->{'Type'} || 'SCALAR';
-    if( $type eq 'ARRAY' ) {
+sub Set {
+    my ($self, $name) = (shift, shift);
+    
+    my $old = $OPTIONS{ $name };
+    my $type = $META{ $name }->{'Type'} || 'SCALAR';
+    if ( $type eq 'ARRAY' ) {
         $OPTIONS{$name} = [ @_ ];
         { no strict 'refs';  @{"RT::$name"} = (@_); }
-    } elsif( $type eq 'HASH' ) {
+    } elsif ( $type eq 'HASH' ) {
         $OPTIONS{$name} = { @_ };
         { no strict 'refs';  %{"RT::$name"} = (@_); }
     } else {
@@ -313,9 +295,19 @@
         { no strict 'refs';  ${"RT::$name"} = $OPTIONS{$name}; }
     }
     $META{$name}->{'Type'} = $type;
+    return $self->_ReturnValue($old, $type);
+}
 
+sub _ReturnValue {
+    my ($self, $res, $type) = @_;
+    return $res unless wantarray;
 
-    return 1;
+    if( $type eq 'ARRAY' ) {
+        return @{ $res };
+    } elsif( $type eq 'HASH' ) {
+        return %{ $res };
+    }
+    return $res;
 }
 
 sub SetFromConfig


More information about the Rt-commit mailing list