[Bps-public-commit] net-lighthouse branch, master, updated. 214f98be93cbdd9e9924c61b048e4389ada1c891
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Fri Sep 11 12:09:38 EDT 2009
The branch, master has been updated
via 214f98be93cbdd9e9924c61b048e4389ada1c891 (commit)
from aa751defa4f3f5f8c287cbe25cb87d9f3e7812a6 (commit)
Summary of changes:
Makefile.PL | 2 +-
lib/Net/Lighthouse.pm | 2 +-
lib/Net/Lighthouse/Util.pm | 40 +++++++++++++++++++++++++---------------
3 files changed, 27 insertions(+), 17 deletions(-)
- Log -----------------------------------------------------------------
commit 214f98be93cbdd9e9924c61b048e4389ada1c891
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sat Sep 12 00:09:34 2009 +0800
s/XML::Simple/XML::TreePP/
diff --git a/Makefile.PL b/Makefile.PL
index e381ede..4a89f7e 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -8,7 +8,7 @@ repository 'git://github.com/bestpractical/net-lighthouse.git';
requires 'Any::Moose';
requires 'Params::Validate';
-requires 'XML::Simple';
+requires 'XML::TreePP';
requires 'LWP';
requires 'MIME::Base64';
requires 'DateTime';
diff --git a/lib/Net/Lighthouse.pm b/lib/Net/Lighthouse.pm
index 3222ebc..b7a8b9c 100644
--- a/lib/Net/Lighthouse.pm
+++ b/lib/Net/Lighthouse.pm
@@ -94,7 +94,7 @@ return a corresponding object, with account and auth prefilled if exist.
=head1 DEPENDENCIES
-L<Any::Moose>, L<Params::Validate>, L<XML::Simple>, L<LWP>, L<MIME::Base64>,
+L<Any::Moose>, L<Params::Validate>, L<XML::TreePP>, L<LWP>, L<MIME::Base64>,
L<YAML::Syck>, L<DateTime>, L<URI::Escape>
=head1 BUGS AND LIMITATIONS
diff --git a/lib/Net/Lighthouse/Util.pm b/lib/Net/Lighthouse/Util.pm
index 0c8b2b7..0963a8d 100644
--- a/lib/Net/Lighthouse/Util.pm
+++ b/lib/Net/Lighthouse/Util.pm
@@ -3,7 +3,12 @@ use warnings;
package Net::Lighthouse::Util;
use DateTime;
-use XML::Simple;
+use XML::TreePP;
+my $tpp = XML::TreePP->new;
+$tpp->set( xml_decl => '' );
+$tpp->set( output_encoding => 'UTF-8' );
+$tpp->set( utf8_flag => 1 );
+$tpp->set( text_node_key => 'content' );
BEGIN {
local $@;
@@ -19,12 +24,12 @@ BEGIN {
sub read_xml {
my $self = shift;
- return XMLin( @_, KeyAttr => [], KeepRoot => 1 );
+ return $tpp->parse( shift );
}
sub write_xml {
my $self = shift;
- return XMLout( @_, KeepRoot => 1 );
+ return $tpp->write(shift);
}
@@ -41,11 +46,12 @@ sub translate_from_xml {
%$ref = map { my $new = $_; $new =~ s/-/_/g; $new => $ref->{$_} } keys %$ref;
for my $k ( keys %$ref ) {
+ $ref->{$k} = '' unless $ref->{$k};
if ( ref $ref->{$k} eq 'HASH' ) {
- if ( $ref->{$k}{nil} && $ref->{$k}{nil} eq 'true' ) {
+ if ( $ref->{$k}{-nil} && $ref->{$k}{-nil} eq 'true' ) {
$ref->{$k} = undef;
}
- elsif ( $ref->{$k}{type} && $ref->{$k}{type} eq 'boolean' ) {
+ elsif ( $ref->{$k}{-type} && $ref->{$k}{-type} eq 'boolean' ) {
if ( $ref->{$k}{content} eq 'true' ) {
$ref->{$k} = 1;
}
@@ -53,22 +59,26 @@ sub translate_from_xml {
$ref->{$k} = 0;
}
}
- elsif ( $ref->{$k}{type} && $ref->{$k}{type} eq 'datetime' ) {
+ elsif ( $ref->{$k}{-type} && $ref->{$k}{-type} eq 'datetime' ) {
$ref->{$k} =
$class->datetime_from_string( $ref->{$k}{content} );
}
- elsif ( $ref->{$k}{type} && $ref->{$k}{type} eq 'yaml' ) {
+ elsif ( $ref->{$k}{-type} && $ref->{$k}{-type} eq 'yaml' ) {
$ref->{$k} = _Load( $ref->{$k}{content} );
}
- elsif ( $ref->{$k}{type} && $ref->{$k}{type} eq 'integer' ) {
- $ref->{$k} =
- defined $ref->{$k}{content} ? $ref->{$k}{content} : undef;
+ elsif ( $ref->{$k}{-type} && $ref->{$k}{-type} eq 'integer' ) {
+ if ( defined $ref->{$k}{content} && $ref->{$k}{content} ne '' ) {
+ $ref->{$k} = $ref->{$k}{content};
+ }
+ else {
+ $ref->{$k} = undef;
+ }
}
elsif ( defined $ref->{$k}{content} ) {
$ref->{$k} = $ref->{$k}{content};
}
elsif ( keys %{ $ref->{$k} } == 0
- || keys %{ $ref->{$k} } == 1 && exists $ref->{$k}{type} )
+ || keys %{ $ref->{$k} } == 1 && exists $ref->{$k}{-type} )
{
$ref->{$k} = '';
}
@@ -89,10 +99,10 @@ sub translate_to_xml {
delete $normal{$_};
next unless exists $ref->{$boolean};
if ( $ref->{$boolean} ) {
- $ref->{$boolean} = { content => 'true', type => 'boolean' };
+ $ref->{$boolean} = { content => 'true', -type => 'boolean' };
}
else {
- $ref->{$boolean} = { content => 'false', type => 'boolean' };
+ $ref->{$boolean} = { content => 'false', -type => 'boolean' };
}
}
}
@@ -109,8 +119,8 @@ sub translate_to_xml {
sub datetime_from_string {
my $class = shift;
my $string = shift;
- if ( $string
- && $string =~
+ return unless $string;
+ if ( $string =~
/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(Z|[+-]\d{2}:\d{2})/ )
{
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list