File-DataClass
view release on metacpan or search on metacpan
lib/File/DataClass/Result.pm view on Meta::CPAN
package File::DataClass::Result;
use namespace::autoclean;
use Moo;
use File::DataClass::Types qw( Object Str );
has 'id' => is => 'rw', isa => Str, required => 1;
has '_result_source' => is => 'ro', isa => Object,
handles => { _path => 'path', _storage => 'storage' },
init_arg => 'result_source', reader => 'result_source',
required => 1, weak_ref => 1;
around 'BUILDARGS' => sub {
my ($orig, $self, @args) = @_; my $attr = $orig->( $self, @args );
my $name = delete $attr->{name}; $attr->{id} //= $name;
return $attr;
};
sub delete {
return $_[ 0 ]->_storage->delete( $_[ 0 ]->_path, $_[ 0 ] );
}
sub insert {
return $_[ 0 ]->_storage->insert( $_[ 0 ]->_path, $_[ 0 ] );
}
sub name { # Deprecated
return defined $_[ 1 ] ? $_[ 0 ]->id( $_[ 1 ] ) : $_[ 0 ]->id;
}
sub update {
return $_[ 0 ]->_storage->update( $_[ 0 ]->_path, $_[ 0 ] );
}
1;
__END__
=pod
=head1 Name
File::DataClass::Result - Result object definition
=head1 Synopsis
=head1 Description
This is analogous to the result object in L<DBIx::Class>
=head1 Configuration and Environment
Defines these attributes
=over 3
=item B<id>
An additional attribute added to the result to store the underlying hash
key
=item B<result_source>
An object reference to the L<File::DataClass::ResultSource> instance for
this result object
=back
=head1 Subroutines/Methods
=head2 BUILDARGS
Replaces the deprecated C<name> attribute with C<id>
=head2 BUILD
Creates accessors and mutators for the attributes defined by the
schema class
=head2 delete
$result->delete;
Calls the delete method in the storage class
=head2 insert
$result->insert;
Calls the insert method in the storage class
( run in 0.479 second using v1.01-cache-2.11-cpan-524268b4103 )