[Bps-public-commit] r16799 - in Prophet/trunk: .

sunnavy at bestpractical.com sunnavy at bestpractical.com
Mon Nov 10 01:38:40 EST 2008


Author: sunnavy
Date: Mon Nov 10 01:38:40 2008
New Revision: 16799

Modified:
   Prophet/trunk/   (props changed)
   Prophet/trunk/lib/Prophet/CLI/Command/Settings.pm

Log:
 r17679 at sunnavys-mb:  sunnavy | 2008-11-10 14:32:47 +0800
 perltidy Prophet::CLI::Command::Settings


Modified: Prophet/trunk/lib/Prophet/CLI/Command/Settings.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/Settings.pm	(original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/Settings.pm	Mon Nov 10 01:38:40 2008
@@ -6,128 +6,136 @@
 extends 'Prophet::CLI::Command';
 with 'Prophet::CLI::TextEditorCommand';
 
-
 # use an editor to edit if no props are specified on the commandline,
 # allowing the creation of a new comment in the process
 sub run {
-    my $self = shift;
+    my $self     = shift;
     my $template = $self->make_template;
 
-    if ($self->context->has_arg('show')) {
-        print $template."\n";
+    if ( $self->context->has_arg('show') ) {
+        print $template. "\n";
         return;
     }
 
     my $settings = $self->app_handle->database_settings;
-    my %settings_by_name = map { $settings->{$_}->[0] => $_   }  keys %$settings;
+    my %settings_by_name = map { $settings->{$_}->[0] => $_ } keys %$settings;
 
-    if ($self->context->has_arg('set')) {
-        for my $name ($self->context->prop_names) {
-            my $uuid = $settings->{$name}->[0];
-            my $s = $self->app_handle->setting(   uuid => $uuid);
-            my $old_value = $s->get_raw; 
-            my $new_value = $self->context->props->{$name}; 
-            print "trying Changed ".$name." from $old_value to $new_value\n"; 
-        if ($old_value ne $new_value) {
-            $s->set( from_json($new_value , { utf8 => 1 }));
-            print "Changed ".$name." from $old_value to $new_value\n"; 
+    if ( $self->context->has_arg('set') ) {
+        for my $name ( $self->context->prop_names ) {
+            my $uuid      = $settings->{$name}->[0];
+            my $s         = $self->app_handle->setting( uuid => $uuid );
+            my $old_value = $s->get_raw;
+            my $new_value = $self->context->props->{$name};
+            print "trying Changed " . $name
+              . " from $old_value to $new_value\n";
+            if ( $old_value ne $new_value ) {
+                $s->set( from_json( $new_value, { utf8 => 1 } ) );
+                print "Changed " . $name . " from $old_value to $new_value\n";
+            }
         }
+        return;
     }
-    return;    
-}
 
     my $done = 0;
 
-    while (!$done) {
-      $done =  $self->try_to_edit( template => \$template);
+    while ( !$done ) {
+        $done = $self->try_to_edit( template => \$template );
     }
 
-};
+}
 
 sub make_template {
     my $self = shift;
 
     my $content = '';
+
     # get all settings records
     my $settings = $self->app_handle->database_settings;
     for my $name ( keys %$settings ) {
-        my @metadata = @{$settings->{$name}};
-        my $s = $self->app_handle->setting(  label => $name, uuid => (shift @metadata), default => [@metadata]);
-    
-        $content .= $self->_make_template_entry($s). "\n\n" ; 
-    
+        my @metadata = @{ $settings->{$name} };
+        my $s        = $self->app_handle->setting(
+            label   => $name,
+            uuid    => ( shift @metadata ),
+            default => [@metadata]
+        );
+
+        $content .= $self->_make_template_entry($s) . "\n\n";
+
     }
 
     return $content;
 }
 
 sub _make_template_entry {
-    my $self = shift;
+    my $self    = shift;
     my $setting = shift;
-    # format each settings record as 
+
+    # format each settings record as
     #
     #  # uuid: uuid
     #  key: value, value, value
     #
 
-    return "# uuid: ".$setting->uuid."\n".$setting->label.": ".
-        to_json($setting->get, { canonical => 1, pretty=> 0, utf8=>1, allow_nonref => 0}  );
-    
-    
+    return
+        "# uuid: " 
+      . $setting->uuid . "\n" 
+      . $setting->label . ": "
+      . to_json( $setting->get,
+        { canonical => 1, pretty => 0, utf8 => 1, allow_nonref => 0 } );
 
 }
 
-
 sub parse_template {
-    my $self = shift;
+    my $self     = shift;
     my $template = shift;
 
     my $uuid = 'NONE';
     my %content;
     my %parsed;
-    for my $line ( split(/\n/,$template)) { 
-        if ($line =~ /^\s*\#\s*uuid\:\s*(.*?)\s*$/) {
+    for my $line ( split( /\n/, $template ) ) {
+        if ( $line =~ /^\s*\#\s*uuid\:\s*(.*?)\s*$/ ) {
             $uuid = $1;
-        } else {
-            push @{$content{$uuid}} , $line;
+        }
+        else {
+            push @{ $content{$uuid} }, $line;
         }
 
     }
 
     for my $uuid ( keys %content ) {
-        my $data = join("\n",@{$content{$uuid}});
-        if ($data =~ /^(.*?)\s*:\s*(.*)\s*$/ms) {
-            my $label = $1;
+        my $data = join( "\n", @{ $content{$uuid} } );
+        if ( $data =~ /^(.*?)\s*:\s*(.*)\s*$/ms ) {
+            my $label   = $1;
             my $content = $2;
-            $parsed{$uuid} = [$label, $content];
+            $parsed{$uuid} = [ $label, $content ];
         }
     }
 
     return \%parsed;
 }
 
-
 sub process_template {
     my $self = shift;
-    my %args = validate( @_, { template => 1, edited => 1, record => 0} );
+    my %args = validate( @_, { template => 1, edited => 1, record => 0 } );
 
-    my $updated     = $args{edited};
-    my ( $config ) = $self->parse_template($updated);
+    my $updated = $args{edited};
+    my ($config) = $self->parse_template($updated);
 
     no warnings 'uninitialized';
     my $settings = $self->app_handle->database_settings;
-    
+
     for my $uuid ( keys %$config ) {
-        my $s = $self->app_handle->setting(   uuid => $uuid);
-        my $old_value = $s->get_raw; 
+        my $s         = $self->app_handle->setting( uuid => $uuid );
+        my $old_value = $s->get_raw;
         my $new_value = $config->{$uuid}->[1];
         chomp $new_value;
-        if ($old_value ne $new_value) {
-            $s->set( from_json($new_value , { utf8 => 1 }));
-            print "Changed ".$config->{$uuid}->[0]." from $old_value to $new_value\n"; 
+        if ( $old_value ne $new_value ) {
+            $s->set( from_json( $new_value, { utf8 => 1 } ) );
+            print "Changed "
+              . $config->{$uuid}->[0]
+              . " from $old_value to $new_value\n";
         }
 
-
     }
     return 1;
 }



More information about the Bps-public-commit mailing list