Frost
view release on metacpan or search on metacpan
lib/Frost.pm view on Meta::CPAN
If the basic attribute B<id> is sweetened with C<auto_id>, the instance
is automatically assigned a UUID - see L<Data::UUID>.
The resulting B<id> is something like C<ECDAEFD4-9247-11DE-9343-7794CBAD412D>.
=item auto_inc
has id => ( auto_inc => true, ... );
has +id => ( auto_inc => true, ... );
If the basic attribute B<id> is sweetened with C<auto_inc>, the
instance is automatically assigned a sequential number: I<highest used
id> + 1, where I<highest used id> = 0 in an empty cemetery.
=back
See L<Frost::Meta::Attribute>
=head1 The Four Commandments of Frost
=head2 Thou shalt absolve no other Moose before Locum
Frost can only store L<Moose> objects, more precisely: objects inheriting
from L<Frost::Locum>.
This does not mean, that each of your old classes must now use
Frost instead of L<Moose>. Migrating is easily possible by
creating or changing a base class from C<use Moose> to C<use
Frost> - i.e.
package My::BaseFoo;
# use Moose;
use Frost;
no Frost;
__PACKAGE__->meta->make_immutable(); # mutable is VERBOTEN
package My::Foo;
use Moose;
extends 'My::BaseFoo';
has my_attr => ( ... );
no Moose;
__PACKAGE__->meta->make_immutable(); # mutable is VERBOTEN
Thus My::Foo and all inheriting classes can be defined the usual L<Moose>
way. The class My::BaseFoo inherits from Frost::Locum, pulling
in all its persistence stuff.
=head2 Thou shalt honor immutability
While applying L<Moose>' tests for Frost it appeared, that reblessing an
object - i.e. because of applying a role at run-time - creates mutable
objects blessed in an anonymous class. This destroys the silence/evoke
mechanism, which depends on the real classname.
So reblessing as well as make_mutable is VERBOTEN.
=head2 Thou shalt not weaken thy reference
Due to Frost's proxy algorithm there is no need for weak references.
See L</MOTIVATION>.
=head2 Thou shalt not create or load objects without an id and thy asylum
To create a new frostable object you must always say:
my $foo = Foo->new ( id => 'a_unique_id', asylum => $asylum, an_attr => ..., another_attr => ... );
$remembered_id = $foo->id;
And to reload a frosted object just say:
my $foo = Foo->new ( id => $remembered_id, asylum => $asylum ); # other params ignored
Or use the Asylum API - a matter of taste:
my $remembered_id = 'a_unique_id';
my $foo = $asylum->silence ( 'Foo', $remembered_id, an_attr => ..., another_attr => ... );
# later...
my $foo = $asylum->evoke ( 'Foo', $remembered_id ); # other params ignored
If the C<id> is defined with C<auto_id> or C<auto_inc>, Asylum is creating a mantra for you - i.e.:
package Bar;
...
has id ( auto_id => 1 );
...
# Create and silence without id:
#
my $bar = Bar->new ( asylum => $asylum, an_attr => ..., another_attr => ... );
my $bar_id = $bar->id; # something like ECDAEFD4-9247-11DE-9343-7794CBAD412D
# Evoke with id:
#
my $bar = Bar->new ( id => $bar_id, asylum => $asylum );
=head1 TODO
Docs, docs, docs...
=head1 GETTING HELP
I'm reading the L<Moose> mailing list frequently, so please ask your
questions there.
The mailing list is L<moose@perl.org>. You must be subscribed to send
a message. To subscribe, send an empty message to
L<moose-subscribe@perl.org>
=head1 DEPENDENCIES
This module requires these other modules and libraries:
( run in 2.727 seconds using v1.01-cache-2.11-cpan-8f98c5d2c55 )