sub collapse_object {
my ( $self, %options ) = @_;
- # NOTE:
- # mark the root object as seen ...
- $self->seen->{refaddr $self->object} = undef;
-
+ # NOTE:
+ # mark the root object as seen ...
+ $self->seen->{refaddr $self->object} = undef;
+
$self->map_attributes('collapse_attribute', \%options);
$self->storage->{$CLASS_MARKER} = $self->object->meta->identifier;
- return $self->storage;
+ return $self->storage;
}
sub expand_object {
$options{check_version} = 1 unless exists $options{check_version};
$options{check_authority} = 1 unless exists $options{check_authority};
- # NOTE:
- # mark the root object as seen ...
- $self->seen->{refaddr $data} = undef;
+ # NOTE:
+ # mark the root object as seen ...
+ $self->seen->{refaddr $data} = undef;
$self->map_attributes('expand_attribute', $data, \%options);
- return $self->storage;
+ return $self->storage;
}
## this is the internal API ...
sub collapse_attribute_value {
my ($self, $attr, $options) = @_;
# Faster, but breaks attributes without readers, do we care?
- #my $value = $attr->get_read_method_ref->($self->object);
- my $value = $attr->get_value($self->object);
+ #my $value = $attr->get_read_method_ref->($self->object);
+ my $value = $attr->get_value($self->object);
- # NOTE:
- # this might not be enough, we might
- # need to make it possible for the
- # cycle checker to return the value
+ # NOTE:
+ # this might not be enough, we might
+ # need to make it possible for the
+ # cycle checker to return the value
$self->check_for_cycle_in_collapse($attr, $value)
if ref $value;
|| confess "Cannot convert " . $attr->type_constraint->name;
$value = $type_converter->{collapse}->($value, $options);
}
- return $value;
+ return $value;
}
sub expand_attribute_value {
my ($self, $attr, $value, $options) = @_;
- # NOTE:
- # (see comment in method above ^^)
+ # NOTE:
+ # (see comment in method above ^^)
if( ref $value and not(
$options->{disable_cycle_check} or
$self->class->does('MooseX::Storage::Traits::DisableCycleDetection')
my $type_converter = $self->find_type_handler($attr->type_constraint, $value);
$value = $type_converter->{expand}->($value, $options);
}
- return $value;
+ return $value;
}
# NOTE:
extends 'MooseX::Storage::Engine::IO::File';
sub store {
- my ($self, $data) = @_;
- my $fh = IO::AtomicFile->new($self->file, 'w')
- || confess "Unable to open file (" . $self->file . ") for storing : $!";
- $fh->binmode(':utf8') if utf8::is_utf8($data);
- print $fh $data;
- $fh->close()
- || confess "Could not write atomic file (" . $self->file . ") because: $!";
+ my ($self, $data) = @_;
+ my $fh = IO::AtomicFile->new($self->file, 'w')
+ || confess "Unable to open file (" . $self->file . ") for storing : $!";
+ $fh->binmode(':utf8') if utf8::is_utf8($data);
+ print $fh $data;
+ $fh->close()
+ || confess "Could not write atomic file (" . $self->file . ") because: $!";
}
1;
=head1 BUGS
-All complex software has bugs lurking in it, and this module is no
+All complex software has bugs lurking in it, and this module is no
exception. If you find a bug please either email me, or add the bug
to cpan-RT.
use IO::File;
has 'file' => (
- is => 'ro',
- isa => 'Str',
- required => 1,
+ is => 'ro',
+ isa => 'Str',
+ required => 1,
);
-sub load {
- my ($self) = @_;
- my $fh = IO::File->new($self->file, 'r')
- || confess "Unable to open file (" . $self->file . ") for loading : $!";
- return do { local $/; <$fh>; };
+sub load {
+ my ($self) = @_;
+ my $fh = IO::File->new($self->file, 'r')
+ || confess "Unable to open file (" . $self->file . ") for loading : $!";
+ return do { local $/; <$fh>; };
}
sub store {
- my ($self, $data) = @_;
- my $fh = IO::File->new($self->file, 'w')
- || confess "Unable to open file (" . $self->file . ") for storing : $!";
- $fh->binmode(':utf8') if utf8::is_utf8($data);
- print $fh $data;
+ my ($self, $data) = @_;
+ my $fh = IO::File->new($self->file, 'w')
+ || confess "Unable to open file (" . $self->file . ") for storing : $!";
+ $fh->binmode(':utf8') if utf8::is_utf8($data);
+ print $fh $data;
}
1;
=head1 BUGS
-All complex software has bugs lurking in it, and this module is no
+All complex software has bugs lurking in it, and this module is no
exception. If you find a bug please either email me, or add the bug
to cpan-RT.
package Point;
use Moose;
use MooseX::Storage;
-
+
with Storage('format' => 'JSON', 'io' => 'File');
-
+
has 'x' => (is => 'rw', isa => 'Int');
has 'y' => (is => 'rw', isa => 'Int');
-
+
has 'foo' => (
metaclass => 'DoNotSerialize',
is => 'rw',
isa => 'CodeRef',
);
-
+
1;
=head1 DESCRIPTION
-Sometimes you don't want a particular attribute to be part of the
-serialization, in this case, you want to make sure that attribute
+
+Sometimes you don't want a particular attribute to be part of the
+serialization, in this case, you want to make sure that attribute
uses this custom meta-attribute. See the SYNOPSIS for a nice example
that can be easily cargo-culted.
=head1 BUGS
-All complex software has bugs lurking in it, and this module is no
+All complex software has bugs lurking in it, and this module is no
exception. If you find a bug please either email me, or add the bug
to cpan-RT.
package Point;
use Moose;
use MooseX::Storage;
-
+
with Storage('format' => 'JSON', 'io' => 'File');
-
+
has 'x' => (is => 'rw', isa => 'Int');
has 'y' => (is => 'rw', isa => 'Int');
-
+
has 'foo' => (
traits => [ 'DoNotSerialize' ],
is => 'rw',
isa => 'CodeRef',
);
-
+
1;
=head1 DESCRIPTION
-Sometimes you don't want a particular attribute to be part of the
-serialization, in this case, you want to make sure that attribute
-uses this custom meta-attribute-trait. See the SYNOPSIS for a nice
+Sometimes you don't want a particular attribute to be part of the
+serialization, in this case, you want to make sure that attribute
+uses this custom meta-attribute-trait. See the SYNOPSIS for a nice
example that can be easily cargo-culted.
=head1 METHODS
=head1 BUGS
-All complex software has bugs lurking in it, and this module is no
+All complex software has bugs lurking in it, and this module is no
exception. If you find a bug please either email me, or add the bug
to cpan-RT.
has 'float' => (is => 'ro', isa => 'Num');
has 'array' => (is => 'ro', isa => 'ArrayRef');
has 'hash' => (is => 'ro', isa => 'HashRef');
- has 'object' => (is => 'ro', isa => 'Object');
+ has 'object' => (is => 'ro', isa => 'Object');
}
my $file = catfile($dir, 'temp.json');
float => 10.5,
array => [ 1 .. 10 ],
hash => { map { $_ => undef } (1 .. 10) },
- object => Foo->new( number => 2 ),
+ object => Foo->new( number => 2 ),
);
isa_ok($foo, 'Foo');
has 'float' => (is => 'ro', isa => 'Num');
has 'array' => (is => 'ro', isa => 'ArrayRef');
has 'hash' => (is => 'ro', isa => 'HashRef');
- has 'object' => (is => 'ro', isa => 'Object');
+ has 'object' => (is => 'ro', isa => 'Object');
}
my $file = catfile($dir, 'temp.json');
float => 10.5,
array => [ 1 .. 10 ],
hash => { map { $_ => undef } (1 .. 10) },
- object => Foo->new( number => 2 ),
+ object => Foo->new( number => 2 ),
);
isa_ok($foo, 'Foo');
float => 10.5,
array => [ 1 .. 10 ],
hash => { map { $_ => undef } (1 .. 10) },
- object => Foo->new( number => 2 ),
+ object => Foo->new( number => 2 ),
);
isa_ok($foo, 'Foo');
has 'float' => (is => 'ro', isa => 'Num');
has 'array' => (is => 'ro', isa => 'ArrayRef');
has 'hash' => (is => 'ro', isa => 'HashRef');
- has 'object' => (is => 'ro', isa => 'Object');
+ has 'object' => (is => 'ro', isa => 'Object');
}
my $file = catfile( $dir, 'temp.json' );
float => 10.5,
array => [ 1 .. 10 ],
hash => { map { $_ => undef } (1 .. 10) },
- object => Foo->new( number => 2 ),
+ object => Foo->new( number => 2 ),
);
isa_ok($foo, 'Foo');
has 'float' => (is => 'ro', isa => 'Num');
has 'array' => (is => 'ro', isa => 'ArrayRef');
has 'hash' => (is => 'ro', isa => 'HashRef');
- has 'object' => (is => 'ro', isa => 'Object');
+ has 'object' => (is => 'ro', isa => 'Object');
}
my $file = catfile($dir,'temp.json');
float => 10.5,
array => [ 1 .. 10 ],
hash => { map { $_ => undef } (1 .. 10) },
- object => Foo->new( number => 2 ),
+ object => Foo->new( number => 2 ),
);
isa_ok($foo, 'Foo');
has 'float' => (is => 'ro', isa => 'Num');
has 'array' => (is => 'ro', isa => 'ArrayRef');
has 'hash' => (is => 'ro', isa => 'HashRef');
- has 'object' => (is => 'ro', isa => 'Object');
+ has 'object' => (is => 'ro', isa => 'Object');
}
my $file = catfile($dir,'temp.storable');
float => 10.5,
array => [ 1 .. 10 ],
hash => { map { $_ => undef } (1 .. 10) },
- object => Foo->new( number => 2 ),
+ object => Foo->new( number => 2 ),
);
isa_ok($foo, 'Foo');
has 'float' => (is => 'ro', isa => 'Num');
has 'array' => (is => 'ro', isa => 'ArrayRef');
has 'hash' => (is => 'ro', isa => 'HashRef');
- has 'object' => (is => 'ro', isa => 'Object');
-
- ## add some custom freeze/thaw hooks here ...
-
+ has 'object' => (is => 'ro', isa => 'Object');
+
+ ## add some custom freeze/thaw hooks here ...
+
sub thaw {
my ( $class, $data ) = @_;
my $self = $class->unpack( $data );
float => 10.5,
array => [ 1 .. 10 ],
hash => { map { $_ => undef } (1 .. 10) },
- object => Foo->new( number => 2 ),
+ object => Foo->new( number => 2 ),
);
isa_ok($foo, 'Foo');