[Bps-public-commit] r11467 - in SVN-PropDB: bin
clkao at bestpractical.com
clkao at bestpractical.com
Thu Apr 3 22:42:40 EDT 2008
Author: clkao
Date: Thu Apr 3 22:42:40 2008
New Revision: 11467
Modified:
SVN-PropDB/bin/sd
SVN-PropDB/lib/Prophet/CLI.pm
SVN-PropDB/lib/Prophet/Collection.pm
SVN-PropDB/lib/Prophet/Record.pm
Log:
- have collection and record classes know better about each other.
- format_summary for different record types.
Modified: SVN-PropDB/bin/sd
==============================================================================
--- SVN-PropDB/bin/sd (original)
+++ SVN-PropDB/bin/sd Thu Apr 3 22:42:40 2008
@@ -20,8 +20,13 @@
package SVB::Model::Ticket;
use base qw/SVB::Record/;
+use constant collection_class => 'SVB::Collection::Ticket';
use constant record_type => 'ticket';
+use constant summary_format => '%u %s %s';
+use constant summary_props => qw(summary status);
+
+
sub validate_status {
my ($self, %args) = @_;
@@ -61,10 +66,20 @@
package SVB::Model::Comment;
use base qw/SVB::Record/;
+use constant collection_class => 'SVB::Collection::Comment';
use constant record_type => 'comment';
+use constant summary_format => '%u %s';
+use constant summary_props => qw(content);
+
#has SVK::Model::Ticket;
+package SVB::Collection::Ticket;
+use base 'Prophet::Collection';
+
+use constant record_class => 'SVB::Model::Ticket';
+
+
package SVB::Collection::Comment;
use base 'Prophet::Collection';
Modified: SVN-PropDB/lib/Prophet/CLI.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/CLI.pm (original)
+++ SVN-PropDB/lib/Prophet/CLI.pm Thu Apr 3 22:42:40 2008
@@ -190,8 +190,9 @@
die "Specify a regular expression and we'll search for records matching that regex";
}
- my $record = $cli->_get_record;
+ my $record = $cli->_get_record;
my $records = $record->collection_class->new( handle => $cli->handle, type => $record->record_type );
+ warn $records;
$records->matching(
sub {
my $item = shift;
@@ -202,7 +203,7 @@
);
for ( @{ $records->as_array_ref } ) {
- printf( "%s %s %s \n", $_->uuid, $_->prop('summary') || "(no summary)", $_->prop('status') || '(no status)' );
+ print $_->format_summary."\n";
}
}
Modified: SVN-PropDB/lib/Prophet/Collection.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Collection.pm (original)
+++ SVN-PropDB/lib/Prophet/Collection.pm Thu Apr 3 22:42:40 2008
@@ -8,6 +8,7 @@
use overload '@{}' => \&as_array_ref, fallback => 1;
__PACKAGE__->mk_accessors(qw'handle type');
+use constant record_class => 'Prophet::Record';
use Prophet::Record;
=head1 NAME
@@ -59,7 +60,7 @@
# run coderef against each item;
# if it matches, add it to _items
foreach my $key ( keys %$nodes ) {
- my $record = Prophet::Record->new( handle => $self->handle, type => $self->type );
+ my $record = $self->record_class->new({ handle => $self->handle, type => $self->type });
$record->load( uuid => $key );
if ( $coderef->($record) ) {
push @{ $self->{_items} }, $record;
Modified: SVN-PropDB/lib/Prophet/Record.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Record.pm (original)
+++ SVN-PropDB/lib/Prophet/Record.pm Thu Apr 3 22:42:40 2008
@@ -36,7 +36,8 @@
sub new {
my $class = shift;
my $self = bless {}, $class;
- my %args = validate( @_, { handle => 1, type => 1 } );
+ my $args = ref($_[0]) ? $_[0] : { @_ };
+ my %args = validate( @{[%$args]}, { handle => 1, type => 1 } );
$self->$_( $args{$_} ) for keys(%args);
return $self;
}
@@ -281,4 +282,24 @@
return $log_ref;
}
+
+=head2 format_summary
+
+returns a formated string that is the summary for the record.
+
+=cut
+
+use constant summary_format => '%u';
+use constant summary_props => ();
+
+sub format_summary {
+ my $self = shift;
+ my $format = $self->summary_format;
+ my $uuid = $self->uuid;
+ $format =~ s/%u/$uuid/g;
+
+ return sprintf( $format, map { $self->prop($_) || "(no $_)" } $self->summary_props );
+
+}
+
1;
More information about the Bps-public-commit
mailing list