[Bps-public-commit] r17497 - in Net-Trac/trunk: .
trs at bestpractical.com
trs at bestpractical.com
Wed Dec 31 16:20:21 EST 2008
Author: trs
Date: Wed Dec 31 16:20:21 2008
New Revision: 17497
Added:
Net-Trac/trunk/lib/Net/Trac/TicketSearch.pm
Modified:
Net-Trac/trunk/ (props changed)
Net-Trac/trunk/lib/Net/Trac/Connection.pm
Net-Trac/trunk/lib/Net/Trac/Ticket.pm
Log:
r43333 at zot: tom | 2008-12-31 15:35:14 -0500
Add ticket search
Modified: Net-Trac/trunk/lib/Net/Trac/Connection.pm
==============================================================================
--- Net-Trac/trunk/lib/Net/Trac/Connection.pm (original)
+++ Net-Trac/trunk/lib/Net/Trac/Connection.pm Wed Dec 31 16:20:21 2008
@@ -99,19 +99,26 @@
sub _csv_to_struct {
my $self = shift;
- my %args = validate( @_, { data => 1, key => 1 } );
+ my %args = validate( @_, { data => 1, key => 1, type => { default => 'hash' } } );
my $csv = Text::CSV_XS->new( { binary => 1 } );
my $x = $args{'data'};
my $io = IO::Scalar->new($x);
my @cols = @{ $csv->getline($io) || [] };
return unless defined $cols[0];
$csv->column_names(@cols);
- my $hashref;
+ my $data;
- while ( my $row = $csv->getline_hr($io) ) {
- $hashref->{ $row->{ $args{'key'} } } = $row;
+ if ( lc $args{'type'} eq 'hash' ) {
+ while ( my $row = $csv->getline_hr($io) ) {
+ $data->{ $row->{ $args{'key'} } } = $row;
+ }
}
- return $hashref;
+ elsif ( lc $args{'type'} eq 'array' ) {
+ while ( my $row = $csv->getline_hr($io) ) {
+ push @$data, $row;
+ }
+ }
+ return $data;
}
1;
Modified: Net-Trac/trunk/lib/Net/Trac/Ticket.pm
==============================================================================
--- Net-Trac/trunk/lib/Net/Trac/Ticket.pm (original)
+++ Net-Trac/trunk/lib/Net/Trac/Ticket.pm Wed Dec 31 16:20:21 2008
@@ -22,8 +22,8 @@
has valid_components => ( isa => 'ArrayRef', is => 'rw' );
has valid_priorities => ( isa => 'ArrayRef', is => 'rw' );
-our @PROPS = qw(cc component description id keywords milestone
- owner priority reporter resolution status summary type);
+our @PROPS = qw( id summary type status priority resolution owner reporter cc
+ description keywords component milestone version );
for my $prop (@PROPS) {
no strict 'refs';
@@ -35,14 +35,17 @@
my ($id) = validate_pos( @_, { type => SCALAR } );
$self->connection->_fetch( "/ticket/" . $id . "?format=csv" );
- my $content = $self->connection->mech->content;
-
- my $stateref
- = $self->connection->_csv_to_struct( data => \$content, key => 'id' );
+ my $content = $self->connection->mech->content;
+ my $stateref = $self->connection->_csv_to_struct( data => \$content, key => 'id' );
return undef unless $stateref;
- $self->state( $stateref->{$id} );
- return $id;
+ return $self->load_from_hashref( $stateref->{$id} );
+}
+sub load_from_hashref {
+ my ($self, $hash) = @_;
+ return undef unless $hash and $hash->{'id'};
+ $self->state( $hash );
+ return $hash->{'id'};
}
sub _get_new_ticket_form {
Added: Net-Trac/trunk/lib/Net/Trac/TicketSearch.pm
==============================================================================
--- (empty file)
+++ Net-Trac/trunk/lib/Net/Trac/TicketSearch.pm Wed Dec 31 16:20:21 2008
@@ -0,0 +1,39 @@
+package Net::Trac::TicketSearch;
+use Moose;
+use Params::Validate qw(:all);
+
+use Net::Trac::Ticket;
+
+has connection => (
+ isa => 'Net::Trac::Connection',
+ is => 'ro'
+);
+
+has limit => ( isa => 'Int', is => 'rw', default => sub { 500 } );
+has results => ( isa => 'ArrayRef', is => 'rw', default => sub { [] } );
+
+sub query {
+ my $self = shift;
+ my %query = @_;
+
+ # Build a URL from the fields we want and the query
+ my $url = '/query?format=csv&order=id&max=' . $self->limit;
+ $url .= '&' . join '&', map { "col=$_" } @Net::Trac::Ticket::PROPS;
+ $url .= '&' . join '&', map { "$_=".$query{$_} } keys %query;
+
+ my $content = $self->connection->_fetch( $url );
+ my $data = $self->connection->_csv_to_struct( data => \$content, key => 'id', type => 'array' );
+
+ my @tickets = ();
+ for ( @{$data || []} ) {
+ my $ticket = Net::Trac::Ticket->new( connection => $self->connection );
+ my $id = $ticket->load_from_hashref( $_ );
+ push @tickets, $ticket if $id;
+ }
+
+ $self->results([]);
+ return $self->results( \@tickets );
+}
+
+1;
+
More information about the Bps-public-commit
mailing list