[Bps-public-commit] r14633 - in Data-Plist: . lib/Data/Plist
alexmv at bestpractical.com
alexmv at bestpractical.com
Wed Jul 30 11:22:48 EDT 2008
Author: alexmv
Date: Wed Jul 30 11:22:47 2008
New Revision: 14633
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/Reader.pm
Data-Plist/lib/Data/Plist/Writer.pm
Log:
r34950 at kohr-ah: chmrr | 2008-07-30 11:19:29 -0400
* Some POD fixups
* Calls to object no longer take a prefix
Modified: Data-Plist/lib/Data/Plist.pm
==============================================================================
--- Data-Plist/lib/Data/Plist.pm (original)
+++ Data-Plist/lib/Data/Plist.pm Wed Jul 30 11:22:47 2008
@@ -11,11 +11,11 @@
-=cut
-
=head1 SERIALIZED DATA
+=head1 KEYED ARCHIVES
+
=cut
@@ -30,9 +30,14 @@
use vars qw/$VERSION/;
$VERSION = "0.1";
+=head1 METHODS
+
=head2 new
-Creates a new plist.
+Creates a new Data::Plist object. Generally, you will not need to
+call this directly, as Plists are generally created by
+L<Data::Plist::Reader> classes, and are not needed in serialization
+when using L<Data::Plist::Writer> classes.
=cut
@@ -71,8 +76,8 @@
=head2 raw_data
-Returns the plist as a set of nested arrays of the format
-[ datatype => $data ].
+Returns the plist as a set of nested arrays of the format specified in
+L</SERIALIZED DATA>.
=cut
@@ -94,8 +99,8 @@
=head2 is_archive
-Checks if the plist is Foundation::LibraryToDo
-object. Returns 1 if true and undef if false.
+Checks if the plist is actually an archived Objective C generated by
+C<NSKeyedArchiver>. Returns true if it is. See L</KEYED ARCHIVES>.
=cut
@@ -146,13 +151,13 @@
sub reify {
my $self = shift;
- my ( $data, $prefix ) = @_;
+ my ( $data ) = @_;
return $data unless ref $data;
if ( ref $data eq "HASH" ) {
my $hash = { %{$data} };
my $class = delete $hash->{'$class'};
- $hash->{$_} = $self->reify( $hash->{$_}, $prefix ) for keys %{$hash};
+ $hash->{$_} = $self->reify( $hash->{$_} ) for keys %{$hash};
if ( $class
and ref $class
and ref $class eq "HASH"
@@ -161,8 +166,8 @@
my $classname = "Foundation::" . $class->{'$classname'};
if ( not $classname->require ) {
warn "Can't require $classname: $@\n";
- } elsif ( not $classname->isa( $prefix . "::NSObject" ) ) {
- warn "$classname isn't a @{[$prefix]}::NSObject\n";
+ } elsif ( not $classname->isa( "Foundation::NSObject" ) ) {
+ warn "$classname isn't a Foundation::NSObject\n";
} else {
bless( $hash, $classname );
$hash = $hash->replacement;
@@ -170,7 +175,7 @@
}
return $hash;
} elsif ( ref $data eq "ARRAY" ) {
- return [ map $self->reify( $_, $prefix ), @{$data} ];
+ return [ map $self->reify( $_ ), @{$data} ];
} else {
return $data;
}
@@ -184,22 +189,47 @@
=head2 object
-Returns an Objective C archive made with NSKeyedArchiver.
+If the plist is an Objective C object archive created with
+C<NSKeyedArchiver> (see L</KEYED ARCHIVES>), returns the object
+blessed into the corresponding class under L<Foundation::NSOjbect>.
+Otherwise, returns undef.
=cut
sub object {
my $self = shift;
- my $prefix = shift;
- my $base = $prefix . "::NSObject";
- unless ( $base->require ) {
- warn "Can't require base class $base: $@\n";
- return;
- }
+ require Foundation::NSObject;
return unless $self->is_archive;
- return $self->reify( $self->collapse( $self->raw_object ), $prefix );
+ return $self->reify( $self->collapse( $self->raw_object ) );
}
+=head1 DEPENDENCIES
+
+L<Class::ISA>, L<DateTime>, L<Digest::MD5>, L<Math::BigInt>,
+L<MIME::Base64>, L<Scalar::Util>, L<Storable>, L<UNIVERSAL::isa>,
+L<XML::Writer>
+
+=head1 BUGS AND LIMITATIONS
+
+No XML reader is included at current.
+
+Please report any bugs or feature requests to
+C<bug-Data-Plist at rt.cpan.org>, or through the web interface at
+L<http://rt.cpan.org>.
+
+=head1 AUTHORS
+
+Alex Vandiver and Jacky Chang.
+
+Based on plutil.pl, written by Pete Wilson <wilsonpm at gamewood.net>
+
+=head1 LICENSE
+
+This module is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself. See L<perlartistic>.
+
+=cut
+
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 30 11:22:47 2008
@@ -33,6 +33,8 @@
use Fcntl qw(:seek);
use Math::BigInt;
+=head1 METHODS
+
=head2 read_misc $type
Takes an integer C<$type> indicating which misc is being
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 30 11:22:47 2008
@@ -17,7 +17,7 @@
=head1 DESCRIPTION
C<Data::Plist::BinaryWriter> takes perl data structures,
-serializes them (see L<Data::Plist/Serialized data>) and
+serializes them (see L<Data::Plist/SERIALIZED DATA>) and
recursively writes to a given filehandle in Apple's binary
property list format.
@@ -38,7 +38,7 @@
=head2 write_fh $fh, $data
Takes a perl data structure C<$data>, serializes it (see
-L<Data::Plist/Serialized data>) and writes it to the given
+L<Data::Plist/SERIALIZED DATA>) and writes it to the given
filehandle C<$fh> in Apple's binary property list format.
The format starts with "bplist00" and contains a 32-byte
@@ -88,7 +88,7 @@
=head2 dispatch $data
Takes serialized data structure C<$data> (see
-L<Data::Plist/Serialized data>) and checks its type. Checks
+L<Data::Plist/SERIALIZED DATA>) and checks its type. Checks
the object against previously written objects. If no match
is found, calls the appropriate write_ method. Returns the
index into the offset table of the offset object that
@@ -184,9 +184,9 @@
=head2 write_string $string
-Takes a UTF-8 encoded string C<$string> and returns the
-index into the offset table of the offset object that
-points to its location in the binary file.
+Takes a string C<$string> and returns the index into the offset table
+of the offset object that points to its location in the binary file.
+It is encoded in the file using UTF-8.
=cut
@@ -200,12 +200,13 @@
=head2 write_ustring $ustring
-Takes a UTF-16 encoded string C<$ustring> and returns the
-index into the offset table of the offset object that
-points to its location in the binary file.
+Takes a string C<$ustring> and returns the index into the offset table
+of the offset object that points to its location in the binary file.
-Currently unimplemented - strings are simply passed on to
-write_string, which treats them as being encoded in UTF-8.
+While C<ustrings> are technically supposed to be stored in UTF-16,
+there is no known reason for them to not be written as UTF-8 encoded
+C<string>s instead; thus, for simplicity, all C<ustring>s are written
+as C<string>s.
=cut
@@ -380,10 +381,11 @@
Takes an integer indicating an object belonging to the misc
category C<$type> (false, null, true or fill) and returns
the index into the offset table of the offset object that
-points to its location in the file. Miscs are a group of
-data types not easily represented in Perl, and they are
-written with the only header byte containing a 0 to
-indicate that they are a misc and their misc type.
+points to its location in the file.
+
+Miscs are a group of data types not easily represented in Perl, and
+they are written with the only header byte containing a 0 to indicate
+that they are a misc and their misc type.
=cut
@@ -424,7 +426,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];
Modified: Data-Plist/lib/Data/Plist/Reader.pm
==============================================================================
--- Data-Plist/lib/Data/Plist/Reader.pm (original)
+++ Data-Plist/lib/Data/Plist/Reader.pm Wed Jul 30 11:22:47 2008
@@ -16,9 +16,9 @@
=head1 DESCRIPTION
C<Data::Plist::Reader> is an abstract superclass of
-BinaryReader. Takes either a string or a filehandle
-containing binary data formatted as an Apple binary
-property list and returns it as a C<Data::Plist>.
+BinaryReader. Takes either a string or a filehandle containing data
+formatted as an Apple property list and returns it as a
+C<Data::Plist>.
=cut
@@ -27,6 +27,8 @@
use strict;
use warnings;
+=head1 METHODS
+
=head2 new
Create a new reader.
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 30 11:22:47 2008
@@ -17,9 +17,9 @@
=head1 DESCRIPTION
C<Data::Plist::Writer> is the abstract superclass of
-BinaryWriter and XMLWriter. It takes perl data structures,
-serializes them (see L<Data::Plist/Serialized data>), and
-recursively writes to a given filehandle in the desired
+L<Data::Plist::BinaryWriter> and L<Data::Plist::XMLWriter>. It takes
+perl data structures, serializes them (see L<Data::Plist/SERIALIZED
+DATA>), and recursively writes to a given filehandle in the desired
format.
=cut
@@ -28,6 +28,7 @@
use strict;
use warnings;
+use Storable;
use Scalar::Util;
=head1 METHODS
@@ -40,6 +41,8 @@
=cut
+# XXX: Doc the serialize argument
+
sub new {
my $class = shift;
my %args = ( serialize => 1, @_ );
@@ -52,10 +55,9 @@
=head2 write $data
-Takes a perl data structure C<$data> and writes to the
-given filehandle C<$filehandle>, or filename
-C<$filename>. Can also write to a string if C<$filehandle>
-is not defined.
+Takes a perl data structure C<$data> and writes to the given
+filehandle C<$filehandle>, or filename C<$filename>. If only the
+C<$data> is provided, returns the data to be written, as a string.
=cut
@@ -89,13 +91,17 @@
=cut
+# XXX This implies that $data is an NSKeyedArchiver. It takes a
+# serialized object, and rewrites it into the format that
+# NSKeyedArchiver would have written, by folding on UIDs.
+
sub fold_uids {
my $self = shift;
my $data = shift;
if ( $data->[0] eq "UID" ) {
require Digest::MD5;
- my $digest = Digest::MD5::md5_hex( YAML::Dump( $data->[1] ) );
+ my $digest = Digest::MD5::md5_hex( Storable::freeze( $data->[1] ) );
if ( exists $self->{objcache}{$digest} ) {
return [ UID => $self->{objcache}{$digest} ];
}
@@ -117,11 +123,12 @@
Takes a perl data structure C<$data> and turns it into a
series of nested arrays of the format [datatype => data]
-(see L<Data::Plist/Serialized data>) in preparation for
+(see L<Data::Plist/SERIALIZED DATA>) in preparation for
writing. This is an internal data structure that should be
immediately handed off to a writer.
=cut
+
sub serialize_value {
my $self = shift;
my ($value) = @_;
@@ -162,7 +169,7 @@
Objects wishing to provide their own serializations should
have a 'serialize' method, which should return something in
the internal structure mentioned above (see also
-L<Data::Plist/Serialized data>).
+L<Data::Plist/SERIALIZED DATA>).
=cut
More information about the Bps-public-commit
mailing list