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

sunnavy at bestpractical.com sunnavy at bestpractical.com
Fri Sep 11 05:14:37 EDT 2009


The branch, master has been updated
       via  b1f2edf797b962eb70f4e111ee093c9a7c7c4457 (commit)
      from  c3568220b2e645645eb12e4889b33e098c35fe2c (commit)

Summary of changes:
 lib/Net/Lighthouse/Project.pm           |    7 +++----
 lib/Net/Lighthouse/Project/Changeset.pm |    5 ++---
 lib/Net/Lighthouse/Project/Message.pm   |    9 ++++-----
 lib/Net/Lighthouse/Project/Milestone.pm |    7 +++----
 lib/Net/Lighthouse/Project/Ticket.pm    |    7 +++----
 lib/Net/Lighthouse/Project/TicketBin.pm |    7 +++----
 lib/Net/Lighthouse/User.pm              |    5 ++---
 lib/Net/Lighthouse/Util.pm              |   14 ++++++++++++--
 8 files changed, 32 insertions(+), 29 deletions(-)

- Log -----------------------------------------------------------------
commit b1f2edf797b962eb70f4e111ee093c9a7c7c4457
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Sep 11 17:14:32 2009 +0800

    gather all xml parse stuff to Util.pm

diff --git a/lib/Net/Lighthouse/Project.pm b/lib/Net/Lighthouse/Project.pm
index fde98fd..a78c984 100644
--- a/lib/Net/Lighthouse/Project.pm
+++ b/lib/Net/Lighthouse/Project.pm
@@ -1,6 +1,5 @@
 package Net::Lighthouse::Project;
 use Any::Moose;
-use XML::Simple;
 use Net::Lighthouse::Util;
 use Params::Validate ':all';
 use Net::Lighthouse::Project::Ticket;
@@ -122,7 +121,7 @@ sub create {
         }
     }
 
-    my $xml = XMLout( { project => \%args }, KeepRoot => 1);
+    my $xml = Net::Lighthouse->write_xml( { project => \%args });
     my $ua = $self->ua;
 
     my $url = $self->base_url . '/projects.xml';
@@ -166,7 +165,7 @@ sub update {
         }
     }
 
-    my $xml = XMLout( { project => \%args }, KeepRoot => 1);
+    my $xml = Net::Lighthouse->write_xml( { project => \%args });
     my $ua = $self->ua;
     my $url = $self->base_url . '/projects/' . $self->id . '.xml';
 
@@ -206,7 +205,7 @@ sub list {
     my $url = $self->base_url . '/projects.xml';
     my $res = $ua->get( $url );
     if ( $res->is_success ) {
-        my $ps = XMLin( $res->content, KeyAttr => [] )->{project};
+        my $ps = Net::Lighthouse::Util->read_xml( $res->content )->{project};
         my @list = map {
             my $p = Net::Lighthouse::Project->new(
                 map { $_ => $self->$_ }
diff --git a/lib/Net/Lighthouse/Project/Changeset.pm b/lib/Net/Lighthouse/Project/Changeset.pm
index 5e1efb7..0968ebd 100644
--- a/lib/Net/Lighthouse/Project/Changeset.pm
+++ b/lib/Net/Lighthouse/Project/Changeset.pm
@@ -1,6 +1,5 @@
 package Net::Lighthouse::Project::Changeset;
 use Any::Moose;
-use XML::Simple;
 use Params::Validate ':all';
 use Net::Lighthouse::Util;
 extends 'Net::Lighthouse::Base';
@@ -88,7 +87,7 @@ sub create {
         $args{$field} = { content => $args{$field} };
     }
 
-    my $xml = XMLout( { changeset => \%args }, KeepRoot => 1);
+    my $xml = Net::Lighthouse->write_xml( { changeset => \%args });
     my $ua = $self->ua;
 
     my $url = $self->base_url . '/projects/' . $self->project_id . '/changesets.xml';
@@ -134,7 +133,7 @@ sub list {
     my $ua  = $self->ua;
     my $res = $ua->get($url);
     if ( $res->is_success ) {
-        my $cs = XMLin( $res->content, KeyAttr => [] )->{changeset};
+        my $cs = Net::Lighthouse::Util->read_xml( $res->content )->{changeset};
         my @list = map {
             my $t = Net::Lighthouse::Project::Changeset->new(
                 map { $_ => $self->$_ }
diff --git a/lib/Net/Lighthouse/Project/Message.pm b/lib/Net/Lighthouse/Project/Message.pm
index ecbca24..27ef2a8 100644
--- a/lib/Net/Lighthouse/Project/Message.pm
+++ b/lib/Net/Lighthouse/Project/Message.pm
@@ -1,6 +1,5 @@
 package Net::Lighthouse::Project::Message;
 use Any::Moose;
-use XML::Simple;
 use Params::Validate ':all';
 use Net::Lighthouse::Util;
 extends 'Net::Lighthouse::Base';
@@ -115,7 +114,7 @@ sub create {
         $args{$field} = { content => $args{$field} };
     }
 
-    my $xml = XMLout( { message => \%args }, KeepRoot => 1);
+    my $xml = Net::Lighthouse->write_xml( { message => \%args });
     my $ua = $self->ua;
 
     my $url = $self->base_url . '/projects/' . $self->project_id . '/messages.xml';
@@ -150,7 +149,7 @@ sub create_comment {
 
     # TODO doc says <message>, but it doesn't work actually.
     # comment can work, though still with a problem
-    my $xml = XMLout( { comment => \%args }, KeepRoot => 1);
+    my $xml = Net::Lighthouse->write_xml( { comment => \%args });
     my $ua = $self->ua;
 
     my $url =
@@ -191,7 +190,7 @@ sub update {
         $args{$field} = { content => $args{$field} };
     }
 
-    my $xml = XMLout( { message => \%args }, KeepRoot => 1);
+    my $xml = Net::Lighthouse->write_xml( { message => \%args });
     my $ua = $self->ua;
     my $url =
         $self->base_url
@@ -241,7 +240,7 @@ sub list {
     my $ua  = $self->ua;
     my $res = $ua->get($url);
     if ( $res->is_success ) {
-        my $ms = XMLin( $res->content, KeyAttr => [] )->{message};
+        my $ms = Net::Lighthouse::Util->read_xml( $res->content )->{message};
         my @list = map {
             my $t = Net::Lighthouse::Project::Message->new(
                 map { $_ => $self->$_ }
diff --git a/lib/Net/Lighthouse/Project/Milestone.pm b/lib/Net/Lighthouse/Project/Milestone.pm
index d942a7b..baa15ae 100644
--- a/lib/Net/Lighthouse/Project/Milestone.pm
+++ b/lib/Net/Lighthouse/Project/Milestone.pm
@@ -1,6 +1,5 @@
 package Net::Lighthouse::Project::Milestone;
 use Any::Moose;
-use XML::Simple;
 use Params::Validate ':all';
 use Net::Lighthouse::Util;
 extends 'Net::Lighthouse::Base';
@@ -95,7 +94,7 @@ sub create {
         $args{$field} = { content => $args{$field} };
     }
 
-    my $xml = XMLout( { milestone => \%args }, KeepRoot => 1);
+    my $xml = Net::Lighthouse->write_xml( { milestone => \%args });
     my $ua = $self->ua;
 
     my $url = $self->base_url . '/projects/' . $self->project_id . '/milestones.xml';
@@ -130,7 +129,7 @@ sub update {
         $args{$field} = { content => $args{$field} };
     }
 
-    my $xml = XMLout( { milestone => \%args }, KeepRoot => 1);
+    my $xml = Net::Lighthouse->write_xml( { milestone => \%args });
     my $ua = $self->ua;
     my $url =
         $self->base_url
@@ -179,7 +178,7 @@ sub list {
     my $ua  = $self->ua;
     my $res = $ua->get($url);
     if ( $res->is_success ) {
-        my $ms = XMLin( $res->content, KeyAttr => [] )->{milestone};
+        my $ms = Net::Lighthouse::Util->read_xml( $res->content )->{milestone};
         my @list = map {
             my $t = Net::Lighthouse::Project::Milestone->new(
                 map { $_ => $self->$_ }
diff --git a/lib/Net/Lighthouse/Project/Ticket.pm b/lib/Net/Lighthouse/Project/Ticket.pm
index b9bcc1f..44d138c 100644
--- a/lib/Net/Lighthouse/Project/Ticket.pm
+++ b/lib/Net/Lighthouse/Project/Ticket.pm
@@ -1,6 +1,5 @@
 package Net::Lighthouse::Project::Ticket;
 use Any::Moose;
-use XML::Simple;
 use Params::Validate ':all';
 use Net::Lighthouse::Util;
 extends 'Net::Lighthouse::Base';
@@ -160,7 +159,7 @@ sub create {
         $args{$field} = { content => $args{$field} };
     }
 
-    my $xml = XMLout( { ticket => \%args }, KeepRoot => 1);
+    my $xml = Net::Lighthouse->write_xml( { ticket => \%args });
     my $ua = $self->ua;
 
     my $url = $self->base_url . '/projects/' . $self->project_id . '/tickets.xml';
@@ -212,7 +211,7 @@ sub update {
         $args{$field} = { content => $args{$field} };
     }
 
-    my $xml = XMLout( { ticket => \%args }, KeepRoot => 1);
+    my $xml = Net::Lighthouse->write_xml( { ticket => \%args });
     my $ua = $self->ua;
     my $url =
         $self->base_url
@@ -278,7 +277,7 @@ sub list {
     my $ua  = $self->ua;
     my $res = $ua->get($url);
     if ( $res->is_success ) {
-        my $ts = XMLin( $res->content, KeyAttr => [] )->{ticket};
+        my $ts = Net::Lighthouse::Util->read_xml( $res->content )->{ticket};
         my @list = map {
             my $t = Net::Lighthouse::Project::Ticket->new(
                 map { $_ => $self->$_ }
diff --git a/lib/Net/Lighthouse/Project/TicketBin.pm b/lib/Net/Lighthouse/Project/TicketBin.pm
index 1863425..ee95daf 100644
--- a/lib/Net/Lighthouse/Project/TicketBin.pm
+++ b/lib/Net/Lighthouse/Project/TicketBin.pm
@@ -1,6 +1,5 @@
 package Net::Lighthouse::Project::TicketBin;
 use Any::Moose;
-use XML::Simple;
 use Params::Validate ':all';
 use Net::Lighthouse::Util;
 extends 'Net::Lighthouse::Base';
@@ -112,7 +111,7 @@ sub create {
         $args{$field} = { content => $args{$field} };
     }
 
-    my $xml = XMLout( { bin => \%args }, KeepRoot => 1 );
+    my $xml = Net::Lighthouse->write_xml( { bin => \%args } );
     my $ua = $self->ua;
 
     my $url = $self->base_url . '/projects/' . $self->project_id . '/bins.xml';
@@ -156,7 +155,7 @@ sub update {
         $args{$field} = { content => $args{$field} };
     }
 
-    my $xml = XMLout( { bin => \%args }, KeepRoot => 1 );
+    my $xml = Net::Lighthouse->write_xml( { bin => \%args } );
     my $ua = $self->ua;
     my $url =
         $self->base_url
@@ -206,7 +205,7 @@ sub list {
     my $ua   = $self->ua;
     my $res  = $ua->get($url);
     if ( $res->is_success ) {
-        my $bs = XMLin( $res->content, KeyAttr => [] )->{'ticket-bin'};
+        my $bs = Net::Lighthouse::Util->read_xml( $res->content )->{'ticket-bin'};
         my @list = map {
             my $t = Net::Lighthouse::Project::TicketBin->new(
                 map { $_ => $self->$_ }
diff --git a/lib/Net/Lighthouse/User.pm b/lib/Net/Lighthouse/User.pm
index 5e66f1d..a4b5b72 100644
--- a/lib/Net/Lighthouse/User.pm
+++ b/lib/Net/Lighthouse/User.pm
@@ -1,6 +1,5 @@
 package Net::Lighthouse::User;
 use Any::Moose;
-use XML::Simple;
 use Params::Validate ':all';
 use Net::Lighthouse::Util;
 extends 'Net::Lighthouse::Base';
@@ -71,7 +70,7 @@ sub update {
         $args{$field} = { content => $args{$field} };
     }
 
-    my $xml = XMLout( { user => \%args }, KeepRoot => 1 );
+    my $xml = Net::Lighthouse->write_xml( { user => \%args } );
     my $ua  = $self->ua;
     my $url = $self->base_url . '/users/' . $self->id . '.xml';
 
@@ -98,7 +97,7 @@ sub memberships {
     my $res  = $ua->get($url);
     require Net::Lighthouse::User::Membership;
     if ( $res->is_success ) {
-        my $ms = XMLin( $res->content, KeyAttr => [] )->{membership};
+        my $ms = Net::Lighthouse::Util->read_xml( $res->content )->{membership};
         my @list = map {
             my $m = Net::Lighthouse::User::Membership->new;
             $m->load_from_xml($_);
diff --git a/lib/Net/Lighthouse/Util.pm b/lib/Net/Lighthouse/Util.pm
index f46d91f..5095730 100644
--- a/lib/Net/Lighthouse/Util.pm
+++ b/lib/Net/Lighthouse/Util.pm
@@ -2,8 +2,8 @@ use strict;
 use warnings;
 
 package Net::Lighthouse::Util;
-use XML::Simple;
 use DateTime;
+use XML::Simple;
 
 BEGIN {
     local $@;
@@ -17,12 +17,22 @@ BEGIN {
     }
 }
 
+sub read_xml {
+    my $self = shift;
+    return XMLin( @_, KeyAttr => [] );
+}
+
+sub write_xml {
+    my $self = shift;
+    return XMLout( @_, KeepRoot => 1 );
+}
+
 
 sub translate_from_xml {
     my $class = shift;
     my $ref = shift;
     return unless $ref;
-    $ref = XMLin( $ref, KeyAttr => [] ) unless ref $ref;
+    $ref = Net::Lighthouse::Util->read_xml( $ref ) unless ref $ref;
     %$ref = map { my $new = $_; $new =~ s/-/_/g; $new => $ref->{$_} } keys %$ref;
     for my $k ( keys %$ref ) {
         if ( ref $ref->{$k} eq 'HASH' ) {

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



More information about the Bps-public-commit mailing list