[Bps-public-commit] r18479 - in Net-Trac/trunk: t
jesse at bestpractical.com
jesse at bestpractical.com
Thu Feb 19 18:46:37 EST 2009
Author: jesse
Date: Thu Feb 19 18:46:36 2009
New Revision: 18479
Modified:
Net-Trac/trunk/lib/Net/Trac/Connection.pm
Net-Trac/trunk/lib/Net/Trac/TicketSearch.pm
Net-Trac/trunk/t/50-full-api.t
Log:
Remove Text::CSV_XS
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 Thu Feb 19 18:46:36 2009
@@ -27,8 +27,6 @@
use Any::Moose;
use URI;
-use Text::CSV_XS;
-use IO::Scalar;
use Params::Validate;
use Net::Trac::Mechanize;
@@ -195,7 +193,7 @@
else { return }
}
-=head2 _csv_to_struct PARAMHASH
+=head2 _tsv_to_struct PARAMHASH
Takes a paramhash of the keys C<data> and C<key> and optionally C<type>.
Given CSV data this method will return a reference to a hash (by default)
@@ -204,23 +202,27 @@
=cut
-sub _csv_to_struct {
+sub _tsv_to_struct {
my $self = shift;
my %args = validate( @_, { data => 1, key => 1, type => 1 } );
- 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 $data;
+ my $x = ${$args{'data'}};
+
+ my $data = [];
+ my @lines = split(/\r\n/,$x);
- if ( lc $args{'type'} eq 'array' ) {
- while ( my $row = $csv->getline_hr($io) ) {
- push @$data, $row;
- }
+
+ my @keys = split(/\t/, shift @lines);
+
+ for my $line (@lines) {
+ my %hash;
+ my @values = split(/\t/,$line);
+
+ $hash{$_} = shift @values for (@keys);
+ push @$data, \%hash;
}
+
return $data;
+
}
=head1 LICENSE
Modified: Net-Trac/trunk/lib/Net/Trac/TicketSearch.pm
==============================================================================
--- Net-Trac/trunk/lib/Net/Trac/TicketSearch.pm (original)
+++ Net-Trac/trunk/lib/Net/Trac/TicketSearch.pm Thu Feb 19 18:46:36 2009
@@ -85,7 +85,7 @@
$self->results([]);
# Build a URL from the fields we want and the query
- my $base = '/query?format=csv&order=id&max=' . $self->limit;
+ my $base = '/query?format=tab&order=id&max=' . $self->limit;
$base .= '&' . join '&', map { "col=$_" } Net::Trac::Ticket->valid_props;
$self->url( $self->_build_query( $base, \%query ) );
@@ -93,7 +93,7 @@
my $content = $self->connection->_fetch( $self->url )
or return;
- my $data = $self->connection->_csv_to_struct( data => \$content, key => 'id', type => 'array' );
+ my $data = $self->connection->_tsv_to_struct( data => \$content, key => 'id', type => 'array' );
unless ( $no_objects ) {
my @tickets = ();
Modified: Net-Trac/trunk/t/50-full-api.t
==============================================================================
--- Net-Trac/trunk/t/50-full-api.t (original)
+++ Net-Trac/trunk/t/50-full-api.t Thu Feb 19 18:46:36 2009
@@ -1,7 +1,7 @@
use Test::More;
unless (`which trac-admin`) { plan skip_all => 'You need trac installed to run the tests'; }
-plan tests => 24;
+plan tests => 26;
use_ok('Net::Trac::Connection');
@@ -38,14 +38,16 @@
like($ticket->summary, qr/moose/, "The summary looks like a moose");
ok( $ticket->update(
- summary => 'The product does not contain a pony'
-
+ summary => 'The product does not contain a pony',
+ description => "This\nis\nmultiline"
), "updated!");
like($ticket->summary, qr/pony/, "The summary looks like a pony");
unlike($ticket->summary, qr/moose/, "The summary does not look like a moose");
+like($ticket->description, qr/This/);
+like($ticket->description, qr/multiline/);
my $history = $ticket->history;
ok($history, "The ticket has some history");
isa_ok($history, 'Net::Trac::TicketHistory');
More information about the Bps-public-commit
mailing list