[Bps-public-commit] net-lighthouse branch, master, updated. 71c09e62c131dda5fada2d01861802bb1f4dcecb

sunnavy at bestpractical.com sunnavy at bestpractical.com
Mon Sep 7 04:48:14 EDT 2009


The branch, master has been updated
       via  71c09e62c131dda5fada2d01861802bb1f4dcecb (commit)
      from  6a049f46ecbf745776742ea37f49c7938d132979 (commit)

Summary of changes:
 lib/Net/Lighthouse/Project.pm           |    7 ++++---
 lib/Net/Lighthouse/Project/Changeset.pm |    8 ++++----
 lib/Net/Lighthouse/Project/Message.pm   |    8 ++++----
 lib/Net/Lighthouse/Project/Milestone.pm |    8 ++++----
 lib/Net/Lighthouse/Project/Ticket.pm    |   21 ++++++++++++++-------
 lib/Net/Lighthouse/Project/TicketBin.pm |    8 ++++----
 t/02-project.t                          |    4 +++-
 t/03-ticket.t                           |    6 +++++-
 t/09-milestone.t                        |    3 ++-
 t/10-changeset.t                        |    3 ++-
 t/11-message.t                          |    3 ++-
 t/12-ticket-bin.t                       |    3 ++-
 12 files changed, 50 insertions(+), 32 deletions(-)

- Log -----------------------------------------------------------------
commit 71c09e62c131dda5fada2d01861802bb1f4dcecb
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Mon Sep 7 16:48:10 2009 +0800

    make list,versions and attachments return array or arrayref by context

diff --git a/lib/Net/Lighthouse/Project.pm b/lib/Net/Lighthouse/Project.pm
index bf311a6..cd8c61e 100644
--- a/lib/Net/Lighthouse/Project.pm
+++ b/lib/Net/Lighthouse/Project.pm
@@ -205,14 +205,15 @@ sub list {
     my $res = $ua->get( $url );
     if ( $res->is_success ) {
         my $ps = XMLin( $res->content, KeyAttr => [] )->{project};
-        $ps = [ $ps ] unless ref $ps eq 'ARRAY';
-        return map {
+        $ps = [$ps] unless ref $ps eq 'ARRAY';
+        my @list = map {
             my $p = Net::Lighthouse::Project->new(
                 map { $_ => $self->$_ }
                   grep { $self->$_ } qw/account auth/
             );
             $p->load_from_xml($_);
-        } @$ps;
+        } ref $ps eq 'ARRAY' ? @$ps : $ps;
+        return wantarray ? @list : \@list;
     }
     else {
         die "try to get $url failed: "
diff --git a/lib/Net/Lighthouse/Project/Changeset.pm b/lib/Net/Lighthouse/Project/Changeset.pm
index 8693b4e..090c03a 100644
--- a/lib/Net/Lighthouse/Project/Changeset.pm
+++ b/lib/Net/Lighthouse/Project/Changeset.pm
@@ -133,15 +133,15 @@ sub list {
     my $ua  = $self->ua;
     my $res = $ua->get($url);
     if ( $res->is_success ) {
-        my $ts = XMLin( $res->content, KeyAttr => [] )->{changeset};
-        $ts = [ $ts ] unless ref $ts eq 'ARRAY';
-        return map {
+        my $cs = XMLin( $res->content, KeyAttr => [] )->{changeset};
+        my @list = map {
             my $t = Net::Lighthouse::Project::Changeset->new(
                 map { $_ => $self->$_ }
                   grep { $self->$_ } qw/account auth project_id/
             );
             $t->load_from_xml($_);
-        } @$ts;
+        } ref $cs eq 'ARRAY' ? @$cs : $cs;
+        return wantarray ? @list : \@list;
     }
     else {
         die "try to get $url failed: "
diff --git a/lib/Net/Lighthouse/Project/Message.pm b/lib/Net/Lighthouse/Project/Message.pm
index 5454b76..f882f94 100644
--- a/lib/Net/Lighthouse/Project/Message.pm
+++ b/lib/Net/Lighthouse/Project/Message.pm
@@ -240,15 +240,15 @@ sub list {
     my $ua  = $self->ua;
     my $res = $ua->get($url);
     if ( $res->is_success ) {
-        my $ts = XMLin( $res->content, KeyAttr => [] )->{message};
-        $ts = [ $ts ] unless ref $ts eq 'ARRAY';
-        return map {
+        my $ms = XMLin( $res->content, KeyAttr => [] )->{message};
+        my @list = map {
             my $t = Net::Lighthouse::Project::Message->new(
                 map { $_ => $self->$_ }
                   grep { $self->$_ } qw/account auth project_id/
             );
             $t->load_from_xml($_);
-        } @$ts;
+        } ref $ms eq 'ARRAY' ? @$ms : $ms;
+        return wantarray ? @list : \@list;
     }
     else {
         die "try to get $url failed: "
diff --git a/lib/Net/Lighthouse/Project/Milestone.pm b/lib/Net/Lighthouse/Project/Milestone.pm
index 95a9bdb..b980ec6 100644
--- a/lib/Net/Lighthouse/Project/Milestone.pm
+++ b/lib/Net/Lighthouse/Project/Milestone.pm
@@ -176,15 +176,15 @@ sub list {
     my $ua  = $self->ua;
     my $res = $ua->get($url);
     if ( $res->is_success ) {
-        my $ts = XMLin( $res->content, KeyAttr => [] )->{milestone};
-        $ts = [ $ts ] unless ref $ts eq 'ARRAY';
-        return map {
+        my $ms = XMLin( $res->content, KeyAttr => [] )->{milestone};
+        my @list = map {
             my $t = Net::Lighthouse::Project::Milestone->new(
                 map { $_ => $self->$_ }
                   grep { $self->$_ } qw/account auth project_id/
             );
             $t->load_from_xml($_);
-        } @$ts;
+        } ref $ms eq 'ARRAY' ? @$ms : $ms;
+        return wantarray ? @list : \@list;
     }
     else {
         die "try to get $url failed: "
diff --git a/lib/Net/Lighthouse/Project/Ticket.pm b/lib/Net/Lighthouse/Project/Ticket.pm
index 6381d4b..feb6efd 100644
--- a/lib/Net/Lighthouse/Project/Ticket.pm
+++ b/lib/Net/Lighthouse/Project/Ticket.pm
@@ -32,13 +32,20 @@ has [
   );
 
 has 'attachments' => (
-    isa => 'ArrayRef[Net::Lighthouse::Project::Ticket::Attachment]',
-    is  => 'ro',
+# TODO Mouse doesn't treat ArrayRef[Net::Lighthouse::Project::Ticket::Attachment]
+# as ArrayRef :/ it's a bug I think
+
+#    isa        => 'ArrayRef[Net::Lighthouse::Project::Ticket::Attachment]',
+    isa        => 'ArrayRef',
+    is         => 'ro',
+    auto_deref => 1,
 );
 
 has 'versions' => (
-    isa => 'ArrayRef[Net::Lighthouse::Project::Ticket::Version]',
-    is  => 'ro',
+#    isa        => 'ArrayRef[Net::Lighthouse::Project::Ticket::Version]',
+    isa        => 'ArrayRef',
+    is         => 'ro',
+    auto_deref => 1,
 );
 
 # read&write attr
@@ -272,14 +279,14 @@ sub list {
     my $res = $ua->get($url);
     if ( $res->is_success ) {
         my $ts = XMLin( $res->content, KeyAttr => [] )->{ticket};
-        $ts = [ $ts ] unless ref $ts eq 'ARRAY';
-        return map {
+        my @list = map {
             my $t = Net::Lighthouse::Project::Ticket->new(
                 map { $_ => $self->$_ }
                   grep { $self->$_ } qw/account auth project_id/
             );
             $t->load_from_xml($_);
-        } @$ts;
+        } ref $ts eq 'ARRAY' ? @$ts : $ts;
+        return wantarray ? @list : \@list;
     }
     else {
         die "try to get $url failed: "
diff --git a/lib/Net/Lighthouse/Project/TicketBin.pm b/lib/Net/Lighthouse/Project/TicketBin.pm
index eddca1c..3497540 100644
--- a/lib/Net/Lighthouse/Project/TicketBin.pm
+++ b/lib/Net/Lighthouse/Project/TicketBin.pm
@@ -190,15 +190,15 @@ sub list {
     my $ua   = $self->ua;
     my $res  = $ua->get($url);
     if ( $res->is_success ) {
-        my $ts = XMLin( $res->content, KeyAttr => [] )->{'ticket-bin'};
-        $ts = [$ts] unless ref $ts eq 'ARRAY';
-        return map {
+        my $bs = XMLin( $res->content, KeyAttr => [] )->{'ticket-bin'};
+        my @list = map {
             my $t = Net::Lighthouse::Project::TicketBin->new(
                 map { $_ => $self->$_ }
                   grep { $self->$_ } qw/account auth project_id/
             );
             $t->load_from_xml($_);
-        } @$ts;
+        } ref $bs eq 'ARRAY' ? @$bs : $bs;
+        return wantarray ? @list : \@list;
     }
     else {
         die "try to get $url failed: "
diff --git a/t/02-project.t b/t/02-project.t
index e7586ba..00a0a8c 100644
--- a/t/02-project.t
+++ b/t/02-project.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 85;
+use Test::More tests => 86;
 use Test::Mock::LWP;
 use DateTime;
 use_ok('Net::Lighthouse::Project');
@@ -134,6 +134,8 @@ is( $projects[1]->id, 36513, 'id of 2nd project' );
 is_deeply( $projects[0], $sd,
     'load and list should return the same info for one project' );
 
+is_deeply( scalar $p->list, \@projects, 'list return array ref in scalar context' );
+
 # test for initial_state
 $Mock_response->mock(
     content => sub {
diff --git a/t/03-ticket.t b/t/03-ticket.t
index ab6bb53..eb02a80 100644
--- a/t/03-ticket.t
+++ b/t/03-ticket.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 72;
+use Test::More tests => 75;
 use Test::Mock::LWP;
 use DateTime;
 use_ok('Net::Lighthouse::Project');
@@ -99,9 +99,12 @@ for my $k ( keys %hash ) {
 }
 
 is( @{$n1->versions}, 1, 'version number' );
+is_deeply( scalar $n1->versions, [ $n1->versions ], 'versions return arrayref in scalar context' );
 isa_ok( $n1->versions->[0], 'Net::Lighthouse::Project::Ticket::Version' );
 is( $n1->versions->[0]->creator_id, 67166, 'version creator_id' );
+
 is( @{$n1->attachments}, 2, 'attachment number' );
+is_deeply( scalar $n1->attachments, [ $n1->attachments ], 'attachments return arrayref in scalar context' );
 isa_ok( $n1->attachments->[0], 'Net::Lighthouse::Project::Ticket::Attachment' );
 is( $n1->attachments->[0]->filename, 'first', 'attachment filename' );
 is( $n1->attachments->[1]->content_type,
@@ -123,6 +126,7 @@ my @list = $ticket->list;
 is( scalar @list, 2, 'list number' );
 is( $list[0]->number, 2, '1st ticket number' );
 is( $list[1]->number, 1, '1st ticket number' );
+is_deeply( scalar $ticket->list, \@list, 'list return array ref in scalar context' );
 
 # test initial_state
 $Mock_response->mock(
diff --git a/t/09-milestone.t b/t/09-milestone.t
index 1a9da01..f26e41e 100644
--- a/t/09-milestone.t
+++ b/t/09-milestone.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 43;
+use Test::More tests => 44;
 use Test::Mock::LWP;
 use DateTime;
 
@@ -103,6 +103,7 @@ $milestone = Net::Lighthouse::Project::Milestone->new(
 my @list = $milestone->list;
 is( scalar @list, 1, 'list number' );
 is( $list[0]->id, 48761, '1st milestone number' );
+is_deeply( scalar $milestone->list, \@list, 'list return array ref in scalar context' );
 
 # test initial_state
 $Mock_response->mock(
diff --git a/t/10-changeset.t b/t/10-changeset.t
index 578be6e..c5ddc81 100644
--- a/t/10-changeset.t
+++ b/t/10-changeset.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 32;
+use Test::More tests => 33;
 use Test::Mock::LWP;
 use DateTime;
 
@@ -85,6 +85,7 @@ $changeset = Net::Lighthouse::Project::Changeset->new(
 my @list = $changeset->list;
 is( scalar @list, 1, 'list number' );
 is( $list[0]->revision, 983, '1st changeset number' );
+is_deeply( scalar $changeset->list, \@list, 'list return array ref in scalar context' );
 
 # test initial_state
 $Mock_response->mock(
diff --git a/t/11-message.t b/t/11-message.t
index 2bfb1a6..1cede50 100644
--- a/t/11-message.t
+++ b/t/11-message.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 53;
+use Test::More tests => 54;
 use Test::Mock::LWP;
 use DateTime;
 
@@ -107,6 +107,7 @@ $message = Net::Lighthouse::Project::Message->new(
 my @list = $message->list;
 is( scalar @list, 1, 'list number' );
 is( $list[0]->id, 20298, 'message id' );
+is_deeply( scalar $message->list, \@list, 'list return array ref in scalar context' );
 
 # test initial_state
 $Mock_response->mock(
diff --git a/t/12-ticket-bin.t b/t/12-ticket-bin.t
index a1d4f49..e853388 100644
--- a/t/12-ticket-bin.t
+++ b/t/12-ticket-bin.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 35;
+use Test::More tests => 36;
 use Test::Mock::LWP;
 use DateTime;
 
@@ -83,4 +83,5 @@ $bin = Net::Lighthouse::Project::TicketBin->new(
 my @list = $bin->list;
 is( scalar @list, 3, 'list number' );
 is( $list[0]->id, 48889, '1st bin number' );
+is_deeply( scalar $bin->list, \@list, 'list return array ref in scalar context' );
 

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list