[Bps-public-commit] r16575 - in Prophet/branches/class-dispatch: . lib/Prophet lib/Prophet/CLI lib/Prophet/CLI/Command t/Settings t/Settings/bin t/Settings/lib t/Settings/lib/App t/Settings/lib/App/Settings t/Settings/t

sartak at bestpractical.com sartak at bestpractical.com
Tue Oct 28 14:14:27 EDT 2008


Author: sartak
Date: Tue Oct 28 14:14:27 2008
New Revision: 16575

Added:
   Prophet/branches/class-dispatch/t/Settings/
   Prophet/branches/class-dispatch/t/Settings/bin/
   Prophet/branches/class-dispatch/t/Settings/bin/settings   (contents, props changed)
   Prophet/branches/class-dispatch/t/Settings/lib/
   Prophet/branches/class-dispatch/t/Settings/lib/App/
   Prophet/branches/class-dispatch/t/Settings/lib/App/Settings/
   Prophet/branches/class-dispatch/t/Settings/lib/App/Settings.pm
   Prophet/branches/class-dispatch/t/Settings/lib/App/Settings/Bug.pm
   Prophet/branches/class-dispatch/t/Settings/lib/App/Settings/CLI.pm
   Prophet/branches/class-dispatch/t/Settings/t/
   Prophet/branches/class-dispatch/t/Settings/t/sync-database-settings.t
Modified:
   Prophet/branches/class-dispatch/   (props changed)
   Prophet/branches/class-dispatch/Makefile.PL
   Prophet/branches/class-dispatch/lib/Prophet/App.pm
   Prophet/branches/class-dispatch/lib/Prophet/CLI/Command/Settings.pm
   Prophet/branches/class-dispatch/lib/Prophet/CLI/TextEditorCommand.pm
   Prophet/branches/class-dispatch/lib/Prophet/Config.pm
   Prophet/branches/class-dispatch/lib/Prophet/Test.pm
   Prophet/branches/class-dispatch/t/lib/TestApp/Bug.pm

Log:
Bring class-dispatch up to trunk

Modified: Prophet/branches/class-dispatch/Makefile.PL
==============================================================================
--- Prophet/branches/class-dispatch/Makefile.PL	(original)
+++ Prophet/branches/class-dispatch/Makefile.PL	Tue Oct 28 14:14:27 2008
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 #
 use inc::Module::Install;
-name('Prophet');
+name('Prophet'); #  App::Settings App::Settings::CLI
 author('clkao and jesse');
 license('Perl');
 
@@ -61,11 +61,12 @@
 #    ],
     'Bonjour support' => [
         -default => 0,
-        'Net::Bonjour',
+        'Net::Bonjour', # Net::Rendezvous::Publish
     ],
 );
 
-all_from('lib/Prophet.pm');
+tests('t/*.t t/*/t/*.t');
+all_from('lib/Prophet.pm'); 
 install_script('bin/prophet');
 auto_install;
 WriteAll();

Modified: Prophet/branches/class-dispatch/lib/Prophet/App.pm
==============================================================================
--- Prophet/branches/class-dispatch/lib/Prophet/App.pm	(original)
+++ Prophet/branches/class-dispatch/lib/Prophet/App.pm	Tue Oct 28 14:14:27 2008
@@ -46,6 +46,18 @@
 
 Prophet::App
 
+=head1 SYNOPSIS
+
+=head1 METHODS
+
+=head2 BUILD
+
+=cut
+
+=head2 default_replica_type
+
+Returns a string of the the default replica type for this application.
+
 =cut
 
 sub default_replica_type {
@@ -53,18 +65,29 @@
     return $ENV{'PROPHET_REPLICA_TYPE'} || DEFAULT_REPLICA_TYPE;
 }
 
+=head2 require
+
+=cut
+
 sub require {
     my $self = shift;
     my $class = shift;
     $self->_require(module => $class);
 }
 
+=head2 try_to_require
+
+=cut
+
 sub try_to_require {
     my $self = shift;
     my $class = shift;
     $self->_require(module => $class, quiet => 1);
 }
 
+=head2 _require
+
+=cut
 
 sub _require {
     my $self = shift;

Modified: Prophet/branches/class-dispatch/lib/Prophet/CLI/Command/Settings.pm
==============================================================================
--- Prophet/branches/class-dispatch/lib/Prophet/CLI/Command/Settings.pm	(original)
+++ Prophet/branches/class-dispatch/lib/Prophet/CLI/Command/Settings.pm	Tue Oct 28 14:14:27 2008
@@ -11,12 +11,36 @@
 # allowing the creation of a new comment in the process
 sub run {
     my $self = shift;
-    my $template_to_edit = $self->make_template;
+    my $template = $self->make_template;
+
+    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;
+
+    if ($self->context->has_arg('set')) {
+        for my $name ($self->context->prop_names) {
+            my $uuid = $settings->{$name}->[0];
+            warn "UUID IS $uuid - name is $name";
+            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;    
+}
 
     my $done = 0;
 
     while (!$done) {
-      $done =  $self->try_to_edit( template => \$template_to_edit);
+      $done =  $self->try_to_edit( template => \$template);
     }
 
 };

Modified: Prophet/branches/class-dispatch/lib/Prophet/CLI/TextEditorCommand.pm
==============================================================================
--- Prophet/branches/class-dispatch/lib/Prophet/CLI/TextEditorCommand.pm	(original)
+++ Prophet/branches/class-dispatch/lib/Prophet/CLI/TextEditorCommand.pm	Tue Oct 28 14:14:27 2008
@@ -2,6 +2,8 @@
 use Moose::Role;
 use Params::Validate qw/validate/;
 
+requires 'process_template';
+
 sub try_to_edit {
     my $self = shift;
     my %args = validate( @_,

Modified: Prophet/branches/class-dispatch/lib/Prophet/Config.pm
==============================================================================
--- Prophet/branches/class-dispatch/lib/Prophet/Config.pm	(original)
+++ Prophet/branches/class-dispatch/lib/Prophet/Config.pm	Tue Oct 28 14:14:27 2008
@@ -1,15 +1,16 @@
 package Prophet::Config;
 use Moose;
 use MooseX::AttributeHelpers;
+use File::Spec;
 use Path::Class;
 
-
 has app_handle => (
     is => 'ro',
     weak_ref => 1,
     isa => 'Prophet::App',
     required => 0
 );
+
 has config_files => ( 
     is => 'rw',
     isa => 'ArrayRef' ,
@@ -33,10 +34,15 @@
     return $_[0]->config->{_aliases};
 }
 
-sub app_config_file { 
+sub app_config_file {
     my $self = shift;
 
-    $ENV{'PROPHET_APP_CONFIG'} || file( $self->app_handle->handle->fs_root => "prophetrc" ) ;
+    return $self->file_if_exists($ENV{'PROPHET_APP_CONFIG'})
+        || $self->file_if_exists(
+            File::Spec->catfile(
+                $self->app_handle->handle->fs_root => 'prophetrc' ))
+        || $self->file_if_exists(
+            File::Spec->catfile( $ENV{'HOME'} => '.prophetrc' ));
 }
 
 #my $singleton;
@@ -82,6 +88,20 @@
     return defined($friendly) ? $friendly : $uuid;
 }
 
+=head2 file_if_exists FILENAME
+
+Returns the given filename if it exists on the filesystem, and an
+empty string otherwise.
+
+=cut
+
+sub file_if_exists {
+    my $self = shift;
+    my $file = shift || ''; # quiet warnings
+
+    return (-e $file) ? $file : '';
+}
+
 __PACKAGE__->meta->make_immutable;
 no Moose;
 
@@ -95,14 +115,15 @@
 
 =head1 SYNOPSIS
 
-    In ~/.prophetrc:
+    In the Prophet config file (see L</app_config_file>):
 
-        prefer_luids: 1
+      prefer_luids: 1
+      summary_format_ticket = %4s },$luid | %-11.11s,status | %-70.70s,summary
 
 =head1 DESCRIPTION
 
-This class represents configuration of Prophet and the application built on top
-of it.
+This class represents the configuration of Prophet and the application built on
+top of it.
 
 =head1 METHODS
 
@@ -114,8 +135,9 @@
 
 =head2 app_config_file
 
-The file which controls configuration for this application.
-C<$PROPHET_REPO/prophetrc>.
+The file which controls configuration for this application
+(the $PROPHET_APP_CONFIG environmental variable, C<$PROPHET_REPO/prophetrc>,
+or C<$HOME/.prophetrc>, in that order).
 
 =head2 load_from_files [files]
 
@@ -136,7 +158,7 @@
 
 =head2 list
 
-List all configuration options
+Lists all configuration options.
 
 =head2 display_name_for_uuid UUID
 

Modified: Prophet/branches/class-dispatch/lib/Prophet/Test.pm
==============================================================================
--- Prophet/branches/class-dispatch/lib/Prophet/Test.pm	(original)
+++ Prophet/branches/class-dispatch/lib/Prophet/Test.pm	Tue Oct 28 14:14:27 2008
@@ -127,6 +127,15 @@
     };
 }
 
+=head2 _mk_cmp_closure EXPECTED, ERROR
+
+Takes references to an array of expected output lines and an array of
+error messages. Returns a subroutine that takes a list
+of output lines and compares them to its expected output lines,
+storing error messages for lines that don't match in ERROR.
+
+=cut
+
 sub _mk_cmp_closure {
     my ( $exp, $err ) = @_;
     my $line = 0;
@@ -149,14 +158,6 @@
         }
 }
 
-=head2 is_script_output SCRIPTNAME \@ARGS, \@STDOUT_MATCH, \@STDERR_MATCH, $MSG
-
-Runs the script, checking to see that its output matches
-
-
-
-=cut
-
 our $RUNCNT;
 
 sub _get_perl_cmd {
@@ -173,6 +174,13 @@
     return @cmd;
 }
 
+=head2 is_script_output SCRIPTNAME \@ARGS, \@STDOUT_MATCH, \@STDERR_MATCH, $MSG
+
+Runs the script, checking to see that its output matches. Error messages
+for lines that don't match are stored in C<\@STDOUT_MATCH>.
+
+=cut
+
 sub is_script_output {
     my ( $script, $arg, $exp_stdout, $exp_stderr, $msg ) = @_;
 
@@ -183,7 +191,7 @@
     my @cmd = _get_perl_cmd($script);
 
     my $ret = run3 [ @cmd, @$arg ], undef, _mk_cmp_closure( $exp_stdout, $stdout_err ),    # stdout
-        _mk_cmp_closure( $exp_stderr, $stdout_err );                                       # stderr
+    _mk_cmp_closure( $exp_stderr, $stdout_err );                    # stderr
 
     for my $line(@$exp_stdout) {
         next if !defined $line;
@@ -193,7 +201,7 @@
     my $test_name = join( ' ', $msg ? "$msg:" : '', $script, @$arg );
     is(scalar(@$stdout_err), 0, $test_name);
     if (@$stdout_err) {
-        diag( "Different in line: " . join( ',', @$stdout_err ) );
+        diag( "Different in line: " . join( "\n", @$stdout_err ) );
     }
 }
 

Added: Prophet/branches/class-dispatch/t/Settings/bin/settings
==============================================================================
--- (empty file)
+++ Prophet/branches/class-dispatch/t/Settings/bin/settings	Tue Oct 28 14:14:27 2008
@@ -0,0 +1,22 @@
+#!/usr/bin/env perl 
+use warnings;
+use strict;
+use App::Settings::CLI;
+use lib 'lib';
+use lib '../../lib';
+# Moose likes generating very noisy backtraces. Most users don't need to see
+# anything more than the root cause of the failure. Developers and the curious
+# can set environment variable SD_VERBOSE_ERROR to retain the backtraces.
+# When Moose's error throwing is more malleable we should switch to using that.
+unless ($ENV{'TEST_VERBOSE'}) {
+    $SIG{__DIE__} = sub {
+        my $line = shift;
+        $line =~ s/\n.*//s if ($line =~ /at line/s);
+        $line .= "\n"; $line =~ s/\n+$/\n/gs;
+        die $line;
+    };
+}
+
+my $cli = App::Settings::CLI->new;
+$cli->run_one_command(@ARGV);
+

Added: Prophet/branches/class-dispatch/t/Settings/lib/App/Settings.pm
==============================================================================
--- (empty file)
+++ Prophet/branches/class-dispatch/t/Settings/lib/App/Settings.pm	Tue Oct 28 14:14:27 2008
@@ -0,0 +1,23 @@
+package App::Settings;
+use Moose;
+
+extends 'Prophet::App';
+our $VERSION = '0.01';
+
+
+sub database_settings {
+{ 
+        statuses            => ['24183C4D-EFD0-4B16-A207-ED7598E875E6' => qw/new open stalled closed/],
+        default_status      => ['2F9E6509-4468-438A-A733-246B3061003E' => 'new' ],
+        components          => ['6CBD84A1-4568-48E7-B90C-F1A5B7BD8ECD' => qw/core ui docs tests/],
+        default_component   => ['0AEC922F-57B1-44BE-9588-816E5841BB18' => 'core'],
+        milestones          => ['1AF5CF74-A6D4-417E-A738-CCE64A0A7F71' => qw/alpha beta 1.0/],
+        default_milestone   => ['BAB613BD-9E25-4612-8DE3-21E4572859EA' => 'alpha']
+};
+
+}
+
+__PACKAGE__->meta->make_immutable;
+
+no Moose;
+1;

Added: Prophet/branches/class-dispatch/t/Settings/lib/App/Settings/Bug.pm
==============================================================================
--- (empty file)
+++ Prophet/branches/class-dispatch/t/Settings/lib/App/Settings/Bug.pm	Tue Oct 28 14:14:27 2008
@@ -0,0 +1,31 @@
+use warnings;
+use strict;
+
+package App::Settings::Bug;
+use Moose;
+extends 'Prophet::Record';
+
+use base qw/Prophet::Record/;
+
+
+sub new { shift->SUPER::new( @_, type => 'bug' ) }
+
+sub validate_prop_name {
+    my $self = shift;
+    my %args = (@_);
+
+    return 1 if ( $args{props}->{'name'} eq 'Jesse' );
+
+    return 0;
+
+}
+
+sub canonicalize_prop_email {
+    my $self = shift;
+    my %args = (@_);
+    $args{props}->{email} = lc( $args{props}->{email} );
+}
+
+sub default_prop_status { 'new' }
+
+1;

Added: Prophet/branches/class-dispatch/t/Settings/lib/App/Settings/CLI.pm
==============================================================================
--- (empty file)
+++ Prophet/branches/class-dispatch/t/Settings/lib/App/Settings/CLI.pm	Tue Oct 28 14:14:27 2008
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl
+package App::Settings::CLI;
+use Moose;
+extends 'Prophet::CLI';
+
+use App::Settings;
+
+has '+app_class' => (
+    default => 'App::Settings',
+);
+
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;
+

Added: Prophet/branches/class-dispatch/t/Settings/t/sync-database-settings.t
==============================================================================
--- (empty file)
+++ Prophet/branches/class-dispatch/t/Settings/t/sync-database-settings.t	Tue Oct 28 14:14:27 2008
@@ -0,0 +1,41 @@
+#!/usr/bin/perl 
+#
+use warnings;
+use strict;
+
+use Prophet::Test tests => 11;
+use lib 't/Settings/lib';
+
+
+as_alice {
+    run_ok( 'settings', [qw(create --type Bug -- --status new --from alice )], "Created a record as alice" );
+    run_output_matches( 'settings', [qw(search --type Bug --regex .)], [qr/new/], " Found our record" );
+    my ($return, $stdout, $stderr) = run_script('settings', [qw(settings --show)]);
+    like($stdout, qr/default_status: \["new"\]/, "the original milestone list is there");
+    run_ok('settings', [qw(settings --set -- default_status ["open"])]);
+    ($return, $stdout, $stderr) = run_script('settings', [qw(settings --show)]);
+    like($stdout, qr/default_status: \["open"\]/, "the original milestone list is there");
+
+
+
+};
+as_bob {
+    run_ok( 'settings', [ 'merge', '--from', repo_uri_for('alice'), '--to', repo_uri_for('bob') ], "Sync ran ok!" );
+    my ($return, $stdout, $stderr) = run_script('settings', [qw(settings --show)]);
+    like($stdout, qr/default_status: \["open"\]/, "the original milestone list is there");
+    run_ok('settings', [qw(settings --set -- default_status ["stalled"])]);
+    ($return, $stdout, $stderr) = run_script('settings', [qw(settings --show)]);
+    like($stdout, qr/default_status: \["stalled"\]/, "the original milestone list is there");
+
+};
+
+
+as_alice {
+    run_ok( 'settings', [ 'merge', '--from', repo_uri_for('bob'), '--to', repo_uri_for('alice') ], "Sync ran ok!" );
+    my ($return, $stdout, $stderr) = run_script('settings', [qw(settings --show)]);
+    like($stdout, qr/default_status: \["stalled"\]/, "the original milestone list is there");
+
+};
+exit;
+
+

Modified: Prophet/branches/class-dispatch/t/lib/TestApp/Bug.pm
==============================================================================
--- Prophet/branches/class-dispatch/t/lib/TestApp/Bug.pm	(original)
+++ Prophet/branches/class-dispatch/t/lib/TestApp/Bug.pm	Tue Oct 28 14:14:27 2008
@@ -5,8 +5,6 @@
 use Moose;
 extends 'Prophet::Record';
 
-use base qw/Prophet::Record/;
-
 
 sub new { shift->SUPER::new( @_, type => 'bug' ) }
 



More information about the Bps-public-commit mailing list