Name
File::DataClass::Schema - Base class for schema definitions
Synopsis
use File::DataClass::Schema;
$schema = File::DataClass::Schema->new
( path => [ qw( path to a file ) ],
result_source_attributes => { source_name => {}, },
tempdir => [ qw( path to a directory ) ] );
$schema->source( 'source_name' )
->attributes( [ qw( list of attr names ) ] );
$rs = $schema->resultset( 'source_name' );
$result = $rs->find( { name => 'id of record to find' } );
$result->$attr_name( $some_new_value );
$result->update;
@result = $rs->search( { 'attr name' => 'some value' } );
Description
Base class for schema definitions. Each record in a data file requires a result source to define it's attributes. Schema subclasses define the result sources and create new result set instances. Result sets can be used to find existing records by their identity field, or to search for result objects. Attributes of result objects can be mutated and then persisted
Configuration and Environment
Registers all result sources defined by the result source attributes
Creates a new instance of the storage class which defaults to File::DataClass::Storage::JSON
Defines these attributes
cache
-
Instantiates and returns the Cache class attribute. Built on demand
cache_attributes
-
Passed to the Cache::Cache constructor
cache_class
-
Classname used to create the cache object. Defaults to File::DataClass::Cache. Can be the dummy class
none
lock
-
Defaults to Class::Null. Can be set via the
builder
attribute. Built on demand log
-
Log object. Typically an instance of Log::Handler
path
-
Path to the file. This is a File::DataClass::IO object that can be coerced from either a string or an array reference
perms
-
Permissions to set on the file if it is created. Defaults to PERMS
result_source_attributes
-
A hash reference of result sources. See File::DataClass::ResultSource
result_source_class
-
The class name used to create result sources when the source registration attribute is instantiated. Acts as a schema wide default of not overridden in the
result_source_attributes
source_registrations
-
A hash ref or registered result sources, i.e. the keys of the
result_source_attributes
hash storage
-
An instance of a subclass of File::DataClass::Storage
storage_attributes
-
Attributes passed to the storage object's constructor
storage_class
-
The name of the storage class to instantiate
tempdir
-
Temporary directory used to store the cache and lock objects disk representation
Subroutines/Methods
BUILDARGS
Constructs the attribute hash passed to the constructor method
dump
$schema->dump( { path => $to_file, data => $data_hash } );
Dumps the data structure to a file. Path defaults to the one specified in the schema definition. Returns the data that was written to the file if successful. Can be called a class or an object method
load
$data_hash = $schema->load( @paths );
Loads and returns the merged data structure from the named files. Paths defaults to the one specified in the schema definition. Data will be read from cache if available and not stale. Can be called a class or an object method
resultset
$rs = $schema->resultset( $source_name );
Returns a resultset object which by default is an instance of File::DataClass::Resultset
source
$source = $schema->source( $source_name );
Returns a result source object which by default is an instance of File::DataClass::ResultSource
sources
@sources = $schema->sources;
Returns a list of all registered result source names
translate
$schema->translate( $args );
Reads a file in one format and writes it back out in another format
Diagnostics
None
Dependencies
- namespace::autoclean
- Class::Null
- File::DataClass
- File::DataClass::Cache
- File::DataClass::Constants
- File::DataClass::Functions
- File::DataClass::ResultSource
- File::DataClass::Storage
- File::DataClass::Types
- Moo
- Unexpected
Incompatibilities
There are no known incompatibilities in this module
Bugs and Limitations
There are no known bugs in this module. Please report problems to the address below. Patches are welcome
Acknowledgements
Larry Wall - For the Perl programming language
Author
Peter Flanigan, <pjfl@cpan.org>
License and Copyright
Copyright (c) 2017 Peter Flanigan. All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic
This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE