[Bps-public-commit] r14445 - in Data-Plist: . lib/Data lib/Data/Plist lib/Foundation
kyoki at bestpractical.com
kyoki at bestpractical.com
Wed Jul 23 19:12:30 EDT 2008
Author: kyoki
Date: Wed Jul 23 19:12:29 2008
New Revision: 14445
Modified:
Data-Plist/ (props changed)
Data-Plist/lib/Data/Plist.pm
Data-Plist/lib/Data/Plist/BinaryReader.pm
Data-Plist/lib/Data/Plist/BinaryWriter.pm
Data-Plist/lib/Data/Plist/Writer.pm
Data-Plist/lib/Data/Plist/XMLWriter.pm
Data-Plist/lib/Foundation/LibraryToDo.pm
Data-Plist/lib/Foundation/NSArray.pm
Data-Plist/lib/Foundation/NSData.pm
Data-Plist/lib/Foundation/NSDate.pm
Data-Plist/lib/Foundation/NSMutableArray.pm
Data-Plist/lib/Foundation/NSMutableData.pm
Data-Plist/lib/Foundation/NSObject.pm
Data-Plist/lib/Foundation/NSURL.pm
Data-Plist/lib/Foundation/ToDo.pm
Data-Plist/lib/Foundation/ToDoAlarm.pm
Data-Plist/lib/Foundation/ToDoAlarms.pm
Data-Plist/t/binary-load.t
Data-Plist/t/binary-object.t
Data-Plist/t/xml-write.t
Log:
r29962 at nyx: kyoki | 2008-07-23 19:12:24 -0400
perltidy
Modified: Data-Plist/lib/Data/Plist.pm
==============================================================================
--- Data-Plist/lib/Data/Plist.pm (original)
+++ Data-Plist/lib/Data/Plist.pm Wed Jul 23 19:12:29 2008
@@ -18,23 +18,23 @@
my $self = shift;
my ($data) = @_;
- unless (ref $data eq "ARRAY") {
+ unless ( ref $data eq "ARRAY" ) {
warn "Got $data?";
return "???";
}
- if ($data->[0] eq "array") {
- return [ map $self->collapse($_), @{$data->[1]} ];
- } elsif ($data->[0] eq "dict") {
- my %dict = %{$data->[1]};
- $dict{$_} = $self->collapse($dict{$_}) for keys %dict;
+ if ( $data->[0] eq "array" ) {
+ return [ map $self->collapse($_), @{ $data->[1] } ];
+ } elsif ( $data->[0] eq "dict" ) {
+ my %dict = %{ $data->[1] };
+ $dict{$_} = $self->collapse( $dict{$_} ) for keys %dict;
return \%dict;
- } elsif ($data->[0] eq "string") {
+ } elsif ( $data->[0] eq "string" ) {
return $data->[1] eq '$null' ? undef : $data->[1];
- } elsif ($data->[0] eq "date") {
- return DateTime->from_epoch( epoch => $data->[1] + 978307200);
- } elsif ($data->[0] eq "UID" and ref $data->[1]) {
- return $self->collapse($data->[1]);
+ } elsif ( $data->[0] eq "date" ) {
+ return DateTime->from_epoch( epoch => $data->[1] + 978307200 );
+ } elsif ( $data->[0] eq "UID" and ref $data->[1] ) {
+ return $self->collapse( $data->[1] );
} else {
return $data->[1];
}
@@ -49,7 +49,7 @@
sub data {
my $self = shift;
- return $self->collapse($self->raw_data);
+ return $self->collapse( $self->raw_data );
}
sub is_archive {
@@ -75,16 +75,22 @@
sub unref {
my $self = shift;
- my $p = shift;
- if ($p->[0] eq "UID") {
- return ["UID", $self->unref( $self->raw_data->[1]{'$objects'}[1][ $p->[1] ] )];
- } elsif ($p->[0] eq "array") {
- return ["array", [map {$self->unref($_)} @{$p->[1]}]]
- } elsif ($p->[0] eq "dict") {
- my %dict = %{$p->[1]};
- $dict{$_} = $self->unref($dict{$_}) for keys %dict;
- return ["dict", \%dict];
- } elsif ($p->[0] eq "data" and ref $p->[1] and $p->[1]->isa("Data::Plist")) {
+ my $p = shift;
+ if ( $p->[0] eq "UID" ) {
+ return [
+ "UID",
+ $self->unref( $self->raw_data->[1]{'$objects'}[1][ $p->[1] ] )
+ ];
+ } elsif ( $p->[0] eq "array" ) {
+ return [ "array", [ map { $self->unref($_) } @{ $p->[1] } ] ];
+ } elsif ( $p->[0] eq "dict" ) {
+ my %dict = %{ $p->[1] };
+ $dict{$_} = $self->unref( $dict{$_} ) for keys %dict;
+ return [ "dict", \%dict ];
+ } elsif ( $p->[0] eq "data"
+ and ref $p->[1]
+ and $p->[1]->isa("Data::Plist") )
+ {
return $p->[1]->raw_object;
} else {
return $p;
@@ -93,27 +99,31 @@
sub reify {
my $self = shift;
- my($data, $prefix) = @_;
+ my ( $data, $prefix ) = @_;
return $data unless ref $data;
- if (ref $data eq "HASH") {
- my $hash = { %{$data} };
+ if ( ref $data eq "HASH" ) {
+ my $hash = { %{$data} };
my $class = delete $hash->{'$class'};
- $hash->{$_} = $self->reify($hash->{$_}, $prefix) for keys %{$hash};
- if ($class and ref $class and ref $class eq "HASH" and $class->{'$classname'}) {
+ $hash->{$_} = $self->reify( $hash->{$_}, $prefix ) for keys %{$hash};
+ if ( $class
+ and ref $class
+ and ref $class eq "HASH"
+ and $class->{'$classname'} )
+ {
my $classname = "Foundation::" . $class->{'$classname'};
- if (not $classname->require) {
+ if ( not $classname->require ) {
warn "Can't require $classname: $@\n";
- } elsif (not $classname->isa($prefix . "::NSObject")) {
+ } elsif ( not $classname->isa( $prefix . "::NSObject" ) ) {
warn "$classname isn't a @{[$prefix]}::NSObject\n";
} else {
- bless($hash, $classname);
+ bless( $hash, $classname );
$hash = $hash->replacement;
}
}
return $hash;
- } elsif (ref $data eq "ARRAY") {
- return [map $self->reify($_, $prefix), @{$data}];
+ } elsif ( ref $data eq "ARRAY" ) {
+ return [ map $self->reify( $_, $prefix ), @{$data} ];
} else {
return $data;
}
@@ -122,21 +132,21 @@
sub raw_object {
my $self = shift;
return unless $self->is_archive;
- return $self->unref($self->raw_data->[1]{'$top'}[1]{root});
+ return $self->unref( $self->raw_data->[1]{'$top'}[1]{root} );
}
sub object {
- my $self = shift;
+ my $self = shift;
my $prefix = shift;
my $base = $prefix . "::NSObject";
- unless ($base->require) {
+ unless ( $base->require ) {
warn "Can't require base class $base: $@\n";
return;
}
-
+
return unless $self->is_archive;
- return $self->reify($self->collapse($self->raw_object), $prefix);
+ return $self->reify( $self->collapse( $self->raw_object ), $prefix );
}
1;
Modified: Data-Plist/lib/Data/Plist/BinaryReader.pm
==============================================================================
--- Data-Plist/lib/Data/Plist/BinaryReader.pm (original)
+++ Data-Plist/lib/Data/Plist/BinaryReader.pm Wed Jul 23 19:12:29 2008
@@ -16,17 +16,13 @@
my ($type) = @_;
if ( $type == 0 ) {
return [ "null", 0 ];
- }
- elsif ( $type == 8 ) {
+ } elsif ( $type == 8 ) {
return [ "false", 0 ];
- }
- elsif ( $type == 9 ) {
+ } elsif ( $type == 9 ) {
return [ "true", 1 ];
- }
- elsif ( $type == 15 ) {
+ } elsif ( $type == 15 ) {
return [ "fill", 15 ];
- }
- else {
+ } else {
return [ "???", $type ];
}
}
@@ -39,22 +35,18 @@
read( $self->{fh}, $buf, 1 << $size );
if ( $size == 0 ) { # 8 bit
$val = unpack( "C", $buf );
- }
- elsif ( $size == 1 ) { # 16 bit
+ } elsif ( $size == 1 ) { # 16 bit
$val = unpack( "n", $buf );
- }
- elsif ( $size == 2 ) { # 32 bit
+ } elsif ( $size == 2 ) { # 32 bit
$val = unpack( "N", $buf );
- }
- elsif ( $size == 3 ) { # 64 bit
+ } elsif ( $size == 3 ) { # 64 bit
my ( $hw, $lw ) = unpack( "NN", $buf );
$val = Math::BigInt->new($hw)->blsft(32)->bior($lw);
if ( $val->bcmp( Math::BigInt->new(2)->bpow(63) ) > 0 ) {
$val -= Math::BigInt->new(2)->bpow(64);
}
- }
- else {
+ } else {
die "Invalid size for integer ($size)";
}
@@ -69,11 +61,9 @@
read( $self->{fh}, $buf, 1 << $size );
if ( $size == 2 ) { # 32 bit
$val = unpack( "f", reverse $buf );
- }
- elsif ( $size == 3 ) { # 64 bit
+ } elsif ( $size == 3 ) { # 64 bit
$val = unpack( "d", reverse $buf );
- }
- else {
+ } else {
die "Invalid size for real ($size)";
}
@@ -84,7 +74,7 @@
my $self = shift;
my ($size) = @_;
die "Invalid size for date ($size)"
- if ( $size > 3 or $size < 2 );
+ if ( $size > 3 or $size < 2 );
# Dates are just stored as floats
return [ "date", $self->read_real($size)->[1] ];
@@ -139,8 +129,9 @@
my $self = shift;
my ($size) = @_;
- return [ "array",
- [ map { $self->binary_read($_) } $self->read_refs($size) ] ];
+ return [
+ "array", [ map { $self->binary_read($_) } $self->read_refs($size) ]
+ ];
}
sub read_dict {
@@ -178,19 +169,19 @@
if ( defined $objNum ) {
die "Bad offset: $objNum"
- unless $objNum < @{ $self->{offsets} };
+ unless $objNum < @{ $self->{offsets} };
seek( $self->{fh}, $self->{offsets}[$objNum], SEEK_SET );
}
# get object type/size
my $buf;
read( $self->{fh}, $buf, 1 )
- or die "Can't read type byte: $!\byte:";
+ or die "Can't read type byte: $!\byte:";
my $size = unpack( "C*", $buf ) & 0x0F; # Low nybble is size
my $objType = unpack( "C*", $buf ) >> 4; # High nybble is type
$size = $self->binary_read->[1]
- if $objType != 0 and $size == 15;
+ if $objType != 0 and $size == 15;
my %types = (
0 => "misc",
@@ -219,11 +210,11 @@
# with "Out of memory" or "panic: memory wrap"; Do some
# error-proofing here.
die "Not a binary plist file\n"
- unless length $str >= 8 and substr( $str, 0, 8 ) eq "bplist00";
+ unless length $str >= 8 and substr( $str, 0, 8 ) eq "bplist00";
die "Read of plist trailer failed\n"
- unless length $str >= 40;
+ unless length $str >= 40;
die "Invalid top object identifier\n"
- unless length $str > 40;
+ unless length $str > 40;
return $self->SUPER::open_string($str);
}
@@ -244,37 +235,32 @@
# get trailer
eval { seek( $self->{fh}, -32, SEEK_END ) }
- or die "Read of plist trailer failed\n";
+ or die "Read of plist trailer failed\n";
my $end = tell( $self->{fh} );
die "Read of plist trailer failed\n"
- unless $end >= 8;
+ unless $end >= 8;
unless ( read( $self->{fh}, $buf, 32 ) == 32 ) {
die "Read of plist trailer failed\n";
}
local $self->{refsize};
my ( $OffsetSize, $NumObjects, $TopObject, $OffsetTableOffset );
- (
- $OffsetSize, $self->{refsize}, $NumObjects, $TopObject,
+ ( $OffsetSize, $self->{refsize}, $NumObjects, $TopObject,
$OffsetTableOffset
) = unpack "x6CC(x4N)3", $buf;
# Sanity check the trailer
if ( $OffsetSize < 1 or $OffsetSize > 4 ) {
die "Invalid offset size\n";
- }
- elsif ( $self->{refsize} < 1 or $self->{refsize} > 2 ) {
+ } elsif ( $self->{refsize} < 1 or $self->{refsize} > 2 ) {
die "Invalid reference size\n";
- }
- elsif ( 2**( 8 * $self->{refsize} ) < $NumObjects ) {
+ } elsif ( 2**( 8 * $self->{refsize} ) < $NumObjects ) {
die
-"Reference size (@{[$self->{refsize}]}) is too small for purported number of objects ($NumObjects)\n";
- }
- elsif ( $TopObject >= $NumObjects ) {
+ "Reference size (@{[$self->{refsize}]}) is too small for purported number of objects ($NumObjects)\n";
+ } elsif ( $TopObject >= $NumObjects ) {
die "Invalid top object identifier\n";
- }
- elsif ($OffsetTableOffset < 8
+ } elsif ( $OffsetTableOffset < 8
or $OffsetTableOffset > $end
or $OffsetTableOffset + $NumObjects * $OffsetSize > $end )
{
@@ -285,27 +271,27 @@
seek( $fh, $OffsetTableOffset, SEEK_SET );
my $offsetTable;
- my $readSize = read( $self->{fh}, $offsetTable, $NumObjects * $OffsetSize );
+ my $readSize
+ = read( $self->{fh}, $offsetTable, $NumObjects * $OffsetSize );
if ( $readSize != $NumObjects * $OffsetSize ) {
die "Offset table read $readSize bytes, expected ",
- $NumObjects * $OffsetSize;
+ $NumObjects * $OffsetSize;
}
- my @Offsets =
- unpack( [ "", "C*", "n*", "(H6)*", "N*" ]->[$OffsetSize], $offsetTable );
+ my @Offsets = unpack( [ "", "C*", "n*", "(H6)*", "N*" ]->[$OffsetSize],
+ $offsetTable );
if ( $OffsetSize == 3 ) {
@Offsets = map { hex($_) } @Offsets;
}
# Catch invalid offset addresses in the offset table
- if (
- grep {
- $_ < 8
- or $_ >= $end
- or ( $_ >= $OffsetTableOffset
+ if (grep {
+ $_ < 8
+ or $_ >= $end
+ or ($_ >= $OffsetTableOffset
and $_ < $OffsetTableOffset + $NumObjects * $OffsetSize )
} @Offsets
- )
+ )
{
die "Invalid address in offset table\n";
}
Modified: Data-Plist/lib/Data/Plist/BinaryWriter.pm
==============================================================================
--- Data-Plist/lib/Data/Plist/BinaryWriter.pm (original)
+++ Data-Plist/lib/Data/Plist/BinaryWriter.pm Wed Jul 23 19:12:29 2008
@@ -21,8 +21,7 @@
$self->{objcache} = {};
if ( $self->{size} >= 2**8 ) {
$self->{refsize} = 2;
- }
- else {
+ } else {
$self->{refsize} = 1;
}
print $fh "bplist00";
@@ -52,7 +51,7 @@
my $digest = eval { Digest::MD5::md5_hex( Storable::freeze($arrayref) ) };
die "Can't $method" unless $self->can($method);
$self->{objcache}{$digest} = $self->$method( $arrayref->[1] )
- unless ( exists $self->{objcache}{$digest} );
+ unless ( exists $self->{objcache}{$digest} );
return $self->{objcache}{$digest};
}
@@ -64,12 +63,11 @@
my $optint = "";
if ( $len < 15 ) {
$type .= sprintf( "%x", $len );
- }
- else {
+ } else {
$type .= "f";
my $optlen = $self->power($len);
- $optint =
- pack( "C" . $self->pack_in($optlen), hex( "1" . $optlen ), $len );
+ $optint = pack( "C" . $self->pack_in($optlen), hex( "1" . $optlen ),
+ $len );
}
$ans = pack( "H*", $type ) . $optint;
@@ -96,10 +94,11 @@
my $lw = Math::BigInt->new($int);
$lw->band( Math::BigInt->new("4294967295") );
- $obj =
- $self->make_type( $type, $len ) . pack( "N", $hw ) . pack( "N", $lw );
- }
- else {
+ $obj
+ = $self->make_type( $type, $len )
+ . pack( "N", $hw )
+ . pack( "N", $lw );
+ } else {
$fmt = $self->pack_in($len);
$obj = pack( "C" . $fmt, hex( $type . $len ), $int );
}
@@ -214,7 +213,7 @@
sub count {
- # this might be slightly over, since it doesn't take into account duplicates
+ # this might be slightly over, since it doesn't take into account duplicates
my $self = shift;
my ($arrayref) = @_;
my $type = $arrayref->[0];
@@ -224,13 +223,11 @@
$value = 1 + @keys;
$value += $_ for map { $self->count( $arrayref->[1]->{$_} ) } @keys;
return $value;
- }
- elsif ( $type eq "array" ) {
+ } elsif ( $type eq "array" ) {
$value = 1;
$value += $_ for map { $self->count($_) } @{ $arrayref->[1] };
return $value;
- }
- else {
+ } else {
return 1;
}
}
@@ -252,21 +249,17 @@
return 3;
# actually refers to 2^3 bytes
- }
- elsif ( $int > 65535 ) {
+ } elsif ( $int > 65535 ) {
return 2;
# actually refers to 2^2 bytes
- }
- elsif ( $int > 255 ) {
+ } elsif ( $int > 255 ) {
return 1;
# I'm sure you see the trend
- }
- elsif ( $int < 0 ) {
+ } elsif ( $int < 0 ) {
return 3;
- }
- else {
+ } else {
return 0;
}
}
@@ -278,18 +271,15 @@
return 4;
# actually refers to 4 bytes
- }
- elsif ( $int > 2**16 ) {
+ } elsif ( $int > 2**16 ) {
return 3;
# actually refers to 3 bytes
- }
- elsif ( $int > 255 ) {
+ } elsif ( $int > 255 ) {
return 2;
# I'm sure you see the trend
- }
- else {
+ } else {
return 1;
}
}
Modified: Data-Plist/lib/Data/Plist/Writer.pm
==============================================================================
--- Data-Plist/lib/Data/Plist/Writer.pm (original)
+++ Data-Plist/lib/Data/Plist/Writer.pm Wed Jul 23 19:12:29 2008
@@ -6,27 +6,27 @@
sub new {
my $class = shift;
- my %args = (serialize => 1, @_);
+ my %args = ( serialize => 1, @_ );
return bless \%args => $class;
}
sub write {
- my $self = shift;
+ my $self = shift;
my $object = pop;
- my $to = shift;
+ my $to = shift;
- if (not $to) {
+ if ( not $to ) {
my $content = '';
my $fh;
open( $fh, ">", \$content );
- $self->write_fh($fh, $object) or return;
+ $self->write_fh( $fh, $object ) or return;
return $content;
- } elsif (ref $to) {
- $self->write_fh($to, $object)
+ } elsif ( ref $to ) {
+ $self->write_fh( $to, $object );
} else {
my $fh;
open( $fh, ">", $to ) or die "Can't open $to for writing: $!";
- $self->write_fh($fh, $object) or return;
+ $self->write_fh( $fh, $object ) or return;
}
return;
}
@@ -35,21 +35,21 @@
my $self = shift;
my $data = shift;
- if ($data->[0] eq "UID") {
+ if ( $data->[0] eq "UID" ) {
require Digest::MD5;
- my $digest = Digest::MD5::md5_hex(YAML::Dump($data->[1]));
- if (exists $self->{objcache}{$digest}) {
+ my $digest = Digest::MD5::md5_hex( YAML::Dump( $data->[1] ) );
+ if ( exists $self->{objcache}{$digest} ) {
return [ UID => $self->{objcache}{$digest} ];
}
- push @{$self->{objects}}, $self->fold_uids($data->[1]);
- $self->{objcache}{$digest} = @{$self->{objects}} - 1;
- return [ UID => @{$self->{objects}} - 1 ];
- } elsif ($data->[0] eq "array") {
- return ["array", [map {$self->fold_uids($_)} @{$data->[1]}]];
- } elsif ($data->[0] eq "dict") {
- my %dict = %{$data->[1]};
- $dict{$_} = $self->fold_uids($dict{$_}) for keys %dict;
- return ["dict", \%dict];
+ push @{ $self->{objects} }, $self->fold_uids( $data->[1] );
+ $self->{objcache}{$digest} = @{ $self->{objects} } - 1;
+ return [ UID => @{ $self->{objects} } - 1 ];
+ } elsif ( $data->[0] eq "array" ) {
+ return [ "array", [ map { $self->fold_uids($_) } @{ $data->[1] } ] ];
+ } elsif ( $data->[0] eq "dict" ) {
+ my %dict = %{ $data->[1] };
+ $dict{$_} = $self->fold_uids( $dict{$_} ) for keys %dict;
+ return [ "dict", \%dict ];
} else {
return $data;
}
@@ -58,7 +58,7 @@
sub serialize_value {
my $self = shift;
my ($value) = @_;
- if (not defined $value) {
+ if ( not defined $value ) {
return [ string => '$null' ];
} elsif ( ref $value ) {
if ( ref $value eq "ARRAY" ) {
@@ -68,10 +68,11 @@
my %hash = %{$value};
$hash{$_} = $self->serialize_value( $hash{$_} ) for keys %hash;
return [ dict => \%hash ];
- } elsif ($value->isa("Foundation::NSObject")) {
+ } elsif ( $value->isa("Foundation::NSObject") ) {
return $value->serialize;
- } elsif ($value->isa("DateTime")) {
- return [ date => $value->epoch - 978307200 + $value->nanosecond / 1e9 ];
+ } elsif ( $value->isa("DateTime") ) {
+ return [ date => $value->epoch - 978307200
+ + $value->nanosecond / 1e9 ];
} else {
die "Can't serialize unknown ref @{[ref $value]}\n";
}
@@ -79,7 +80,7 @@
return [ integer => $value ];
} elsif ( Scalar::Util::looks_like_number($value) ) {
return [ real => $value ];
- } elsif ( $value =~ /\0/) {
+ } elsif ( $value =~ /\0/ ) {
return [ data => $value ];
} else {
return [ string => $value ];
@@ -87,11 +88,13 @@
}
sub serialize {
- my $self = shift;
+ my $self = shift;
my $object = shift;
return $self->serialize_value($object)
- if not ref($object) or ref($object) =~ /ARRAY|HASH/ or not $object->can("serialize");
+ if not ref($object)
+ or ref($object) =~ /ARRAY|HASH/
+ or not $object->can("serialize");
$object = $object->serialize;
Modified: Data-Plist/lib/Data/Plist/XMLWriter.pm
==============================================================================
--- Data-Plist/lib/Data/Plist/XMLWriter.pm (original)
+++ Data-Plist/lib/Data/Plist/XMLWriter.pm Wed Jul 23 19:12:29 2008
@@ -14,15 +14,15 @@
my ( $fh, $object ) = @_;
local $self->{x}
= XML::Writer->new( OUTPUT => $fh, DATA_MODE => 1, DATA_INDENT => 8 );
- $self->{x}->xmlDecl( "UTF-8" );
+ $self->{x}->xmlDecl("UTF-8");
$self->{x}->doctype(
"plist",
"-//Apple//DTD PLIST 1.0//EN",
"http://www.apple.com/DTDs/PropertyList-1.0.dtd"
);
$self->{x}->startTag( plist => version => "1.0" );
- $object = $self->serialize($object) if ($self->{serialize});
- $self->xml_write( $object );
+ $object = $self->serialize($object) if ( $self->{serialize} );
+ $self->xml_write($object);
$self->{x}->endTag("plist");
$self->{x}->end();
@@ -38,6 +38,7 @@
} elsif ( $data->[0] =~ /^(integer|real|date|string|ustring)$/ ) {
$self->{x}->dataElement( $data->[0], $data->[1] );
} elsif ( $data->[0] eq "UID" ) {
+
# UIDs are only hackishly supported in the XML version.
# Apple's plutil converts them as follows:
$self->{x}->startTag("dict");
Modified: Data-Plist/lib/Foundation/LibraryToDo.pm
==============================================================================
--- Data-Plist/lib/Foundation/LibraryToDo.pm (original)
+++ Data-Plist/lib/Foundation/LibraryToDo.pm Wed Jul 23 19:12:29 2008
@@ -21,42 +21,43 @@
keys_digest => "ToDo Keys Digest",
);
-my %lookup = (reverse %mapping);
-
+my %lookup = ( reverse %mapping );
sub init {
my $self = shift;
- __PACKAGE__->mk_accessors(grep {not $self->can($_)} keys %mapping);
- $self->{$lookup{$_}} = delete $self->{$_} for grep {exists $lookup{$_}} keys %{$self};
+ __PACKAGE__->mk_accessors( grep { not $self->can($_) } keys %mapping );
+ $self->{ $lookup{$_} } = delete $self->{$_}
+ for grep { exists $lookup{$_} } keys %{$self};
- $self->due(undef) unless delete $self->{"ToDo Due Date Enabled"};
+ $self->due(undef) unless delete $self->{"ToDo Due Date Enabled"};
$self->priority(undef) unless delete $self->{"ToDo Priority Enabled"};
}
sub serialize_equiv {
my $self = shift;
my $hash = {};
- $hash->{$mapping{$_}} = $self->{$_} for keys %{$self};
+ $hash->{ $mapping{$_} } = $self->{$_} for keys %{$self};
return $hash;
}
sub serialize {
my $self = shift;
- my $ret = $self->SUPER::serialize;
- $ret->[1]{"ToDo Completed"} = $self->{complete} ? [ true => 1 ] : [ false => 0 ];
- if ($self->{due}) {
+ my $ret = $self->SUPER::serialize;
+ $ret->[1]{"ToDo Completed"}
+ = $self->{complete} ? [ true => 1 ] : [ false => 0 ];
+ if ( $self->{due} ) {
$ret->[1]{"ToDo Due Date Enabled"} = [ true => 1 ];
} else {
delete $ret->[1]{"ToDo Due Date"};
$ret->[1]{"ToDo Due Date Enabled"} = [ false => 0 ];
}
- if (defined $self->{priority}) {
+ if ( defined $self->{priority} ) {
$ret->[1]{"ToDo Priority Enabled"} = [ true => 1 ];
} else {
- $ret->[1]{"ToDo Priority"} = [ integer => 1 ];
- $ret->[1]{"ToDo Priority Enabled"} = [ false => 0 ];
+ $ret->[1]{"ToDo Priority"} = [ integer => 1 ];
+ $ret->[1]{"ToDo Priority Enabled"} = [ false => 0 ];
}
return $ret;
Modified: Data-Plist/lib/Foundation/NSArray.pm
==============================================================================
--- Data-Plist/lib/Foundation/NSArray.pm (original)
+++ Data-Plist/lib/Foundation/NSArray.pm Wed Jul 23 19:12:29 2008
@@ -7,4 +7,3 @@
1;
-
Modified: Data-Plist/lib/Foundation/NSData.pm
==============================================================================
--- Data-Plist/lib/Foundation/NSData.pm (original)
+++ Data-Plist/lib/Foundation/NSData.pm Wed Jul 23 19:12:29 2008
@@ -7,4 +7,3 @@
1;
-
Modified: Data-Plist/lib/Foundation/NSDate.pm
==============================================================================
--- Data-Plist/lib/Foundation/NSDate.pm (original)
+++ Data-Plist/lib/Foundation/NSDate.pm Wed Jul 23 19:12:29 2008
@@ -8,18 +8,18 @@
sub replacement {
my $self = shift;
my $dt = DateTime->from_epoch( epoch => $self->{"NS.time"} + 978307200 );
- bless $dt, (ref $self);
+ bless $dt, ( ref $self );
return $dt;
}
sub serialize_equiv {
my $self = shift;
- my $secs = ($self->epoch - 978307200);
+ my $secs = ( $self->epoch - 978307200 );
$secs += $self->nanosecond / 1e9;
- $secs .= ".0" unless $secs =~ /\D/; # This forces it to be stored as "real"
+ $secs .= ".0"
+ unless $secs =~ /\D/; # This forces it to be stored as "real"
return { "NS.time" => $secs };
}
1;
-
Modified: Data-Plist/lib/Foundation/NSMutableArray.pm
==============================================================================
--- Data-Plist/lib/Foundation/NSMutableArray.pm (original)
+++ Data-Plist/lib/Foundation/NSMutableArray.pm Wed Jul 23 19:12:29 2008
@@ -17,4 +17,3 @@
1;
-
Modified: Data-Plist/lib/Foundation/NSMutableData.pm
==============================================================================
--- Data-Plist/lib/Foundation/NSMutableData.pm (original)
+++ Data-Plist/lib/Foundation/NSMutableData.pm Wed Jul 23 19:12:29 2008
@@ -14,9 +14,8 @@
sub serialize_equiv {
my $self = shift;
return $self->SUPER::serialize_equiv unless ref $self->data;
- return { "NS.data" => Data::Plist::BinaryWriter->write($self->data) };
+ return { "NS.data" => Data::Plist::BinaryWriter->write( $self->data ) };
}
1;
-
Modified: Data-Plist/lib/Foundation/NSObject.pm
==============================================================================
--- Data-Plist/lib/Foundation/NSObject.pm (original)
+++ Data-Plist/lib/Foundation/NSObject.pm Wed Jul 23 19:12:29 2008
@@ -40,7 +40,7 @@
sub serialize_equiv {
my $self = shift;
- return { %{ $self } };
+ return { %{$self} };
}
sub serialize {
@@ -48,9 +48,9 @@
my %dict;
$dict{'$class'} = $self->serialize_class;
my $equiv = $self->serialize_equiv;
- for my $key (keys %{$equiv}) {
- my $value = Data::Plist::Writer->serialize_value($equiv->{$key});
- if ($value->[0] =~ /^(data|integer|real|true|false)$/) {
+ for my $key ( keys %{$equiv} ) {
+ my $value = Data::Plist::Writer->serialize_value( $equiv->{$key} );
+ if ( $value->[0] =~ /^(data|integer|real|true|false)$/ ) {
$dict{$key} = $value;
} else {
$dict{$key} = [ UID => $value ];
Modified: Data-Plist/lib/Foundation/NSURL.pm
==============================================================================
--- Data-Plist/lib/Foundation/NSURL.pm (original)
+++ Data-Plist/lib/Foundation/NSURL.pm Wed Jul 23 19:12:29 2008
@@ -7,8 +7,8 @@
sub replacement {
my $self = shift;
- my $uri = URI->new($self->{"NS.relative"}, "http");
- bless $uri, (ref $self);
+ my $uri = URI->new( $self->{"NS.relative"}, "http" );
+ bless $uri, ( ref $self );
return $uri;
}
Modified: Data-Plist/lib/Foundation/ToDo.pm
==============================================================================
--- Data-Plist/lib/Foundation/ToDo.pm (original)
+++ Data-Plist/lib/Foundation/ToDo.pm Wed Jul 23 19:12:29 2008
@@ -7,4 +7,3 @@
1;
-
Modified: Data-Plist/lib/Foundation/ToDoAlarm.pm
==============================================================================
--- Data-Plist/lib/Foundation/ToDoAlarm.pm (original)
+++ Data-Plist/lib/Foundation/ToDoAlarm.pm Wed Jul 23 19:12:29 2008
@@ -8,7 +8,8 @@
sub serialize {
my $self = shift;
my $ret = $self->SUPER::serialize;
- $ret->[1]{"ToDo Alarm Enabled"} = $ret->[1]{"ToDo Alarm Enabled"}[1] ? [ true => 1 ] : [ false => 0 ];
+ $ret->[1]{"ToDo Alarm Enabled"}
+ = $ret->[1]{"ToDo Alarm Enabled"}[1] ? [ true => 1 ] : [ false => 0 ];
return $ret;
}
Modified: Data-Plist/lib/Foundation/ToDoAlarms.pm
==============================================================================
--- Data-Plist/lib/Foundation/ToDoAlarms.pm (original)
+++ Data-Plist/lib/Foundation/ToDoAlarms.pm Wed Jul 23 19:12:29 2008
@@ -7,4 +7,3 @@
1;
-
Modified: Data-Plist/t/binary-load.t
==============================================================================
--- Data-Plist/t/binary-load.t (original)
+++ Data-Plist/t/binary-load.t Wed Jul 23 19:12:29 2008
@@ -65,7 +65,8 @@
# Data overlap
$ret = eval {
- $read->open_string( "bplist00" . pack( "Cx6CC(x4N)3", 8, 1, 1, 1, 0, 8 ) );
+ $read->open_string(
+ "bplist00" . pack( "Cx6CC(x4N)3", 8, 1, 1, 1, 0, 8 ) );
};
ok( not($ret), "data overlaps with trailer" );
like( "$@", qr/invalid address/i, "Threw an error" );
@@ -89,14 +90,16 @@
# Offset table has too early address
$ret = eval {
- $read->open_string( "bplist00" . pack( "Cx6CC(x4N)3", 0, 1, 1, 1, 0, 8 ) );
+ $read->open_string(
+ "bplist00" . pack( "Cx6CC(x4N)3", 0, 1, 1, 1, 0, 8 ) );
};
ok( not($ret), "address too small" );
like( "$@", qr/invalid address/i, "Threw an error" );
# Offset table has too late address
$ret = eval {
- $read->open_string( "bplist00" . pack( "Cx6CC(x4N)3", 10, 1, 1, 1, 0, 8 ) );
+ $read->open_string(
+ "bplist00" . pack( "Cx6CC(x4N)3", 10, 1, 1, 1, 0, 8 ) );
};
ok( not($ret), "address too small" );
like( "$@", qr/invalid address/i, "Threw an error" );
@@ -153,8 +156,8 @@
like( "$@", qr/invalid offset/i, "Threw an error" );
# Refsize is too small for NumObjects
-my $string =
- do { local @ARGV = "t/data/longfile-03.binary.plist"; local $/; <> };
+my $string
+ = do { local @ARGV = "t/data/longfile-03.binary.plist"; local $/; <> };
ok( $string, "Read from file." );
use bytes;
substr( $string, -25, 1, "\x01" );
@@ -200,14 +203,12 @@
# Test raw structure
is_deeply(
$ret->raw_data,
- [
- dict => {
+ [ dict => {
a => [
array => [
[ integer => 1 ],
[ integer => 2 ],
- [
- dict => {
+ [ dict => {
foo => [ string => "bar" ],
baz => [ string => "troz" ],
zort => [ string => '$null' ],
Modified: Data-Plist/t/binary-object.t
==============================================================================
--- Data-Plist/t/binary-object.t (original)
+++ Data-Plist/t/binary-object.t Wed Jul 23 19:12:29 2008
@@ -11,9 +11,8 @@
my $ret;
my $read = Data::Plist::BinaryReader->new;
my $p = $read->open_file("t/data/todo.plist");
-my $o =
- $p->object("Foundation"); # Should return a Foundation::LibraryTodo, which
- # isa Foundation::NSObject
+my $o = $p->object("Foundation"); # Should return a Foundation::LibraryTodo, which
+ # isa Foundation::NSObject
isa_ok( $o, "Foundation::NSObject" );
my $s = Data::Plist::BinaryWriter->write($o); # Returns a binary plist
ok( $s, "Write successful." );
Modified: Data-Plist/t/xml-write.t
==============================================================================
--- Data-Plist/t/xml-write.t (original)
+++ Data-Plist/t/xml-write.t Wed Jul 23 19:12:29 2008
@@ -7,9 +7,9 @@
my $out;
-
# Dict
-one_way( { "kitteh" => "Angleton" }, '<?xml version="1.0" encoding="UTF-8"?>
+one_way(
+ { "kitteh" => "Angleton" }, '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
@@ -18,10 +18,12 @@
<string>Angleton</string>
</dict>
</plist>
-' );
+'
+);
# Array
-one_way( [ "Cthulhu", 42, "a" ], '<?xml version="1.0" encoding="UTF-8"?>
+one_way(
+ [ "Cthulhu", 42, "a" ], '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
@@ -31,10 +33,12 @@
<string>a</string>
</array>
</plist>
-');
+'
+);
# UID
-preserialize( [ UID => 1 ],'<?xml version="1.0" encoding="UTF-8"?>
+preserialize(
+ [ UID => 1 ], '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
@@ -43,56 +47,69 @@
<integer>1</integer>
</dict>
</plist>
-' );
+'
+);
# Miscs
-preserialize( [ false => 0 ], '<?xml version="1.0" encoding="UTF-8"?>
+preserialize(
+ [ false => 0 ], '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<false />
</plist>
-' );
-preserialize( [ true => 1 ], '<?xml version="1.0" encoding="UTF-8"?>
+'
+);
+preserialize(
+ [ true => 1 ], '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<true />
</plist>
-' );
-preserialize( [ fill => 15 ], '<?xml version="1.0" encoding="UTF-8"?>
+'
+);
+preserialize(
+ [ fill => 15 ], '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<fill />
</plist>
-' );
-preserialize( [ null => 0 ], '<?xml version="1.0" encoding="UTF-8"?>
+'
+);
+preserialize(
+ [ null => 0 ], '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<null />
</plist>
-' );
+'
+);
# Data
-preserialize( [ data => "stu\x00ff" ], '<?xml version="1.0" encoding="UTF-8"?>
+preserialize(
+ [ data => "stu\x00ff" ], '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<data>c3R1AGZm
</data>
</plist>
-');
+'
+);
# Not one of the prescribes structures
-preserialize( [ random => 17 ], '<?xml version="1.0" encoding="UTF-8"?>
+preserialize(
+ [ random => 17 ], '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<!-- random -->
</plist>
-');
+'
+);
sub one_way {
my $write = Data::Plist::XMLWriter->new( serialize => 1 );
@@ -105,11 +122,11 @@
}
sub test {
- my ($write, $input, $output) = @_;
+ my ( $write, $input, $output ) = @_;
ok( $write, "Created XML writer." );
isa_ok( $write, "Data::Plist::XMLWriter" );
$out = $write->write($input);
ok( $out, "Created xml." );
is( "$@", '' );
- is ($out, $output, "XML output is correct.")
+ is( $out, $output, "XML output is correct." );
}
More information about the Bps-public-commit
mailing list