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

Giddy::StaticDirectory - A Giddy directory of static files.

VERSION

version 0.012_002

SYNOPSIS

        my $dir = $coll->get_static_dir('static_files');

        my $fh = $dir->open_text_file("robots.txt");
        $fh->print("User-agent: *\nDisallow:");
        $fh->close;

        $db->stage('static_files');
        $db->commit('create a static-file directory');

DESCRIPTION

This class represents Giddy static-file directories, which are directories that contain files which aren't documents and do not change often, most probably binary files (pictures, videos, songs) and other files which are often called "static" in the world of websites. Any sub-directory in a static directory is also considered a static directory, with infinite nestability.

ATTRIBUTES

path

The relative path of the directory. Always has a starting slash. Required.

coll

The Giddy::Collection object the directory belongs to. This is even if the directory is not a direct child of the collection, but some descendant of it. Required.

OBJECT METHODS

list_files()

Returns a list of all static files in the directory.

list_dirs()

Returns a list of all child directories in the directory. These are all considered static-file directories as well.

get_static_dir( $name )

Returns a Giddy::StaticDirectory object for a child directory of the current directory named $name. If the directory does not exist, it will be created. If a file named $name exists in the directory, this method will croak.

open_text_file( $name, [ $mode ] )

Creates a new file named $name (if not exists) inside the static directory, opens it and returns a IO::File object handle. If $mode is not provided, '>:utf8' is used (meaning the file is truncated (if exists) and opened for writing with automatic UTF-8 encoding of written data). You can provide other modes if you wish, but keep in mind that Giddy expects all your files to be UTF-8.

open_binary_file( $name, [ $mode, $layer ] )

Creates a new file named $name (if not exists) inside the static directory, opens it, binmodes it and returns a IO::File object handle. If $mode isn't provided, '>' is used (meaning the file is truncated (if exists) and opened for writing). If your provide a layer string is provided, it will be passed to binmode() when calling it.

read_file( $name )

Returns the contents of the file named $name in the static directory. Assumes the file exists and has been indexed, will croak if not.

AUTHOR

Ido Perlmuter, <ido at ido50.net>

BUGS

Please report any bugs or feature requests to bug-giddy at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Giddy. 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 Giddy::StaticDirectory

You can also look for information at:

LICENSE AND COPYRIGHT

Copyright 2011 Ido Perlmuter.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.