CatalystX::CRUD::Model::File(3)

NAME
CatalystX::CRUD::Model::File - filesystem CRUD model

SYNOPSIS
 package MyApp::Model::Foo;
 use base qw( CatalystX::CRUD::Model::File );
 __PACKAGE__->config(
    object_class    => 'MyApp::File',
    delegate_class  => 'Path::Class::File', # optional
    inc_path        => [ '/some/path', '/other/path' ],
 );

 1;

DESCRIPTION
CatalystX::CRUD::Model::File is an example implementation of CatalystX::CRUD::Model.

METHODS
Only new or overridden methods are documented here.

  Xsetup
Implements the CXC::Model API. Sets the inc_path() (if not already set) to the "root" config value.

  new_object( file => path/to/file )
Return a new CatalystX::CRUD::Object::File object.

  fetch( file => path/to/file )
Read path/to/file from disk and return a CXCO::File object.

path/to/file is assumed to be in "inc_path"

If path/to/file is empty, the CatalystX::CRUD::Object::File object is returned but its content() will be undef. If its parent dir is '.', its dir() will be set to the first item in inc_path().

If path/to/file is not found, undef is returned.

  prep_new_object( file )
Searches inc_path() and calls file read() method if file is found.

Also verifies that the delegate() has an absolute path set.

Called internally by fetch().

Returns file.

  inc_path
Returns the include path from config(). The include path is searched by search(), count() and iterator().

  make_query
Returns a wanted subroutine suitable for File::Find.

 # TODO regex vs exact match

  search( filter_CODE )
Uses File::Find to search through inc_path() for files. filter_CODE should be a CODE ref matching format returned by make_query(). If not set, make_query() is called by default.

Returns an array ref of CXCO::File objects.

  count( filter_CODE )
Returns number of files matching filter_CODE. See search for a description of filter_CODE.

  iterator( filter_CODE )
Acts same as search() but returns a CatalystX::CRUD::Iterator::File object instead of a simple array ref.

  iterator_related( file, rel_name )
Required method. Acts like iterator() for rel_name.

  add_related( file, rel_name, other_file_name, overwrite )
For rel_name of "dir" will create a symlink for other_file_name's basename to file in the same directory as file.

If a file already exists for other_file_name in the same dir as file will throw an error indicating the relationship already exists. To stop the error being thrown, pass a true value for the overwrite param.

If the symlink fails, will throw_error().

If symlink() is not supported on your system, will print an error to the Catalyst log.

  put_related( file, rel_name, other_file_name )
Calls add_related() with overwrite option.

  rm_related( file, rel_name, other_file_name )
For rel_name of "dir" will create a symlink for other_file_name's basename to file in the same directory as file.

If the symlink() function is not supported, will log an error and return without doing anything.

If the symlink represented by other_file_name does not exist or is not a symlink, will throw an error.

If the unlink fails will also throw an error.

AUTHOR
Peter Karman, "<perl at peknet.com>"

BUGS
Please report any bugs or feature requests to "bug-catalystx-crud at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CatalystX-CRUD>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT
You can find documentation for this module with the perldoc command.

    perldoc CatalystX::CRUD

You can also look for information at:

•   AnnoCPAN: Annotated CPAN documentation

    <http://annocpan.org/dist/CatalystX-CRUD>

•   CPAN Ratings

    <http://cpanratings.perl.org/d/CatalystX-CRUD>

•   RT: CPAN's request tracker

    <http://rt.cpan.org/NoAuth/Bugs.html?Dist=CatalystX-CRUD>

•   Search CPAN

    <http://search.cpan.org/dist/CatalystX-CRUD>

COPYRIGHT & LICENSE
Copyright 2007 Peter Karman, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.