Data-Plist
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Data/Plist.pm view on Meta::CPAN
$ret = $plist->object;
=head1 DESCRIPTION
Plists are intermediate structures from which nested array
structures of the format specified in L</SERIALIZED DATA>,
perl data structures and Objective C data structures can be
obtained.
=cut
=head1 SERIALIZED DATA
Perl data structures that have been serialized become
nested array structures containing their data and their
data type. Example:
[ array => [ string => "kitten" ], [ integer => 42], [ real => 3.14159 ] ]
Array references are passed around when dealing with
serialized data.
=head1 KEYED ARCHIVES
Apple uses binary property lists as a serialization format from
Objective C, in a format C<NSKeyedArchiver>. L<Data::Plist> has the
capability to recognize property lists which were generated using
C<NSKeyedArchiver>, and to construct perl objects based on the
information in the property list. Objects thus created are blessed
under the C<Data::Plist::Foundation> namespace. Thus, the root
ancestor of all Objective C objects thus imported is
L<Data::Plist::Foundation::NSObject>.
=cut
package Data::Plist;
use strict;
use warnings;
use DateTime;
use UNIVERSAL::require;
use vars qw/$VERSION/;
$VERSION = "0.1";
=head1 METHODS
=head2 new
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
sub new {
my $class = shift;
return bless { data => undef, @_ } => $class;
}
=head2 collapse $data
Takes an array of serialized data C<$data>. Recursively
returns the actual data, without the datatype labels.
=cut
sub collapse {
my $self = shift;
my ($data) = @_;
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;
return \%dict;
} 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] );
} else {
return $data->[1];
}
}
=head2 raw_data
Returns the plist as a set of nested arrays of the format specified in
L</SERIALIZED DATA>.
=cut
sub raw_data {
my $self = shift;
return $self->{data};
}
=head2 data
Returns the plist as its corresponding perl data structure.
=cut
sub data {
my $self = shift;
return $self->collapse( $self->raw_data );
}
=head2 is_archive
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.479 second using v1.00-cache-2.02-grep-82fe00e-cpan-1925d2aa809 )