mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2009-03-21 11:03 pm

[dw-free] Allow DW::Setting modules to be fully supported.

[commit: http://hg.dwscoalition.org/dw-free/rev/4a890b60b27c]

Allow DW::Setting modules to be fully supported.

Patch by [personal profile] exor674.

Files modified:
  • cgi-bin/LJ/Setting.pm
  • htdocs/settings/index.bml
--------------------------------------------------------------------------------
diff -r ef00e8e44daa -r 4a890b60b27c cgi-bin/LJ/Setting.pm
--- a/cgi-bin/LJ/Setting.pm	Sat Mar 21 23:00:20 2009 +0000
+++ b/cgi-bin/LJ/Setting.pm	Sat Mar 21 23:03:45 2009 +0000
@@ -5,7 +5,8 @@ use LJ::ModuleLoader;
 use LJ::ModuleLoader;
 
 # Autouse all settings
-LJ::ModuleLoader->autouse_subclasses("LJ::Setting");
+LJ::ModuleLoader->autouse_subclasses( "LJ::Setting" );
+LJ::ModuleLoader->autouse_subclasses( "DW::Setting" );
 
 # ----------------------------------------------------------------------------
 
@@ -45,9 +46,7 @@ sub save {
 
     my %posted;  # class -> key -> value
     while (my ($k, $v) = each %$postargs) {
-        next unless $k =~ /^LJ__Setting__([a-zA-Z0-9]+)_(\w+)$/;
-        my $class = "LJ::Setting::$1";
-        my $key = $2;
+        my ( $class, $key ) = class_from_key( $k );
         $posted{$class}{$key} = $v;
     }
 
@@ -60,6 +59,16 @@ sub save {
 # ----------------------------------------------------------------------------
 
 # Don't override:
+
+# Internal method to do *proper* argument -> class/key mapping.
+sub class_from_key {
+    my ( $val ) = @_;
+
+    my ( $class, $key ) = $val =~ /^((?:[a-zA-Z0-9]+__)+[a-zA-Z0-9]+)_(\w+)$/;
+    $class =~ s/__/::/g if $class;
+
+    return ( $class, $key );
+}
 
 sub pkgkey {
     my $class = shift;
@@ -84,14 +93,14 @@ sub errdiv {
 
 # don't override this.
 sub errors {
-    my ($class, %map) = @_;
+    my ( $class, %map ) = @_;
 
     my $errclass = $class;
-    $errclass =~ s/^LJ::Setting:://;
-    $errclass = "LJ::Error::SettingSave::" . $errclass;
-    eval "\@${errclass}::ISA = ('LJ::Error::SettingSave');";
+    $errclass =~ s/^([a-zA-Z0-9]+)::Setting:://;
+    $errclass = "$1::Error::SettingSave::" . $errclass;
+    eval "\@${errclass}::ISA = ( 'LJ::Error::SettingSave' );";
 
-    my $eo = eval { $errclass->new(map => \%map) };
+    my $eo = eval { $errclass->new( map => \%map ) };
     $eo->log;
     $eo->throw;
 }
@@ -136,15 +145,13 @@ sub error_map {
 # returns any errors and the post args for each setting
 sub save_all {
     shift if $_[0] eq __PACKAGE__;
-    my ($u, $post, $all_settings) = @_;
+    my ( $u, $post, $all_settings ) = @_;
     my %posted;  # class -> key -> value
     my %returns;
 
-    while (my ($k, $v) = each %$post) {
-        next unless $k =~ /^LJ__Setting__([a-zA-Z0-9]+)_(\w+)$/;
-        my $class = "LJ::Setting::$1";
-        my $key = $2;
-        $class =~ s/__/::/g;
+    while ( my ( $k, $v ) = each %$post ) {
+        my ( $class, $key ) = class_from_key( $k );
+        next unless $class;
         $posted{$class}{$key} = $v;
     }
 
diff -r ef00e8e44daa -r 4a890b60b27c htdocs/settings/index.bml
--- a/htdocs/settings/index.bml	Sat Mar 21 23:00:20 2009 +0000
+++ b/htdocs/settings/index.bml	Sat Mar 21 23:03:45 2009 +0000
@@ -22,7 +22,7 @@
     my $selminiclass = $GET{c};   # classname without LJ::Setting::
     my $selclass = $selminiclass ? "LJ::Setting::$selminiclass" : "";
 
-    my @settings = map { s!.+cgi-bin/!!; s!/!::!g; s/\.pm$//; $_ } (glob "$LJ::HOME/cgi-bin/LJ/Setting/*.pm");
+    my @settings = map { s!.+cgi-bin/!!; s!/!::!g; s/\.pm$//; $_ } ( glob "$LJ::HOME/cgi-bin/LJ/Setting/*.pm", glob "$LJ::HOME/cgi-bin/DW/Setting/*.pm" );
 
     my $tag = lc $GET{tag};
     my %tags = ();
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org