The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

Name

File::DataClass::Schema - Base class for schema definitions

Version

This document describes version v0.19.$Rev: 1 $

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( q(source_name) )->attributes( [ qw(list of attr names) ] );
   $rs = $schema->resultset( q(source_name) );
   $result = $rs->find( { name => q(id of field element to find) } );
   $result->$attr_name( $some_new_value );
   $result->update;
   @result = $rs->search( { 'attr name' => q(some value) } );

Description

Base class for schema definitions. Each element in a data file requires a result source to define it's attributes

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::XML::Simple

Defines these attributes

cache

Instantiates and returns the Cache class attribute. Built on demand

cache_attributes

Passed to the Cache::Cache constructor

debug

Writes debug information to the log object if set to true

exception_class

A classname that is expected to have a class method throw. Defaults to File::DataClass::Exception and is of type File::DataClass::Exception

builder

An optional object that provides these methods; debug, exception_class, lock, log, and tempdir. Their values are or'ed with values in the attributes hash before being passed to the constructor

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 ref

perms

Permissions to set on the file if it is created. Defaults to PERMS

result_source_attributes

A hash ref 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_base

If the storage class is only a partial classname then this attribute is prepended to it

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

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

extensions

   \%extension_map = $self->extensions;

Returns a hash ref that maps filename extensions (keys) onto storage subclasses (values)

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

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

Setting the debug attribute to true will cause the log object's debug method to be called with useful information

Dependencies

namespace::autoclean
Class::Null
File::DataClass
File::DataClass::Cache
File::DataClass::Constants
File::DataClass::Exception
File::DataClass::Functions
File::DataClass::ResultSource
File::DataClass::Storage
IPC::SRLock
Moose

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, <Support at RoxSoft.co.uk>

License and Copyright

Copyright (c) 2013 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