Bernard Simon > App-Followme-1.06 > App::Followme::Module

Download:
App-Followme-1.06.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 1.06   Source   Latest Release: App-Followme-1.10

NAME ^

App::Followme::Module - Base class for modules invoked from configuration

SYNOPSIS ^

    use App::Followme::Module;
    my $hs = App::Followme::Module->new($configuration);
    my $prototype = $hs->find_prototype($directory, 0);
    my $test = $hs->is_newer($filename, $prototype);
    if ($test) {
        my $data = $hs->set_fields($directory, $filename);
        my $sub = $self->make_template($directory, $template_name);
        my $webppage = $sub->($data);
        print $webpage;
    }

DESCRIPTION ^

This module contains the methods that build variables and perform template and prototype handling. It serves as the basis of all the computations performed by App::Followme, and thus is used as the base class for all its modules.

A Template is a file containing commands and variables for making a web page. First, the template is compiled into a subroutine and then the subroutine is called with a hash as an argument to fill in the variables and produce a web page. A prototype is the most recently modified web page in a directory. It is combined with the template so that the web page has the same look as the other pages in the directory.

METHODS ^

This module has three public methods.

$test = $self->is_newer($target, @sources);

Compare the modification date of the target file to the modification dates of the source files. If the target file is newer than all of the sources, return 1 (true).

$filename = $self->find_prototype($directory, $uplevel);

Return the name of the most recently modified web page in a directory. If $uplevel is defined, search that many directory levels up from the directory passed as the first argument.

$sub = $self->make_template($directory, $template_name);

Combine a prototype and template, compile them, and return the compiled subroutine. The prototype is the most recently modified file in the directory passed as the first argument. The method searches for the template file first in the directory and if it is not found there, in the templates folder, which is an object parameter,

The data supplied to the subroutine should be a hash reference. fields in the hash are substituted into variables in the template. Variables in the template are preceded by Perl sigils, so that a link would look like:

    <li><a href="$url">$title</a></li>

The data hash may contain a list of hashes, which the modules in App::Followme name loop. Text in between for and endfor comments will be repeated for each hash in the list and each hash will be interpolated into the text. For comments look like

    <!-- for @loop -->
    <!-- endfor -->
$data = $self->set_fields($directory, $filename);

The main method for getting variables. This method calls the build methods defined in this class. Filename is the file that the variables are being computed for. Directory is used to compute the relative url. The url computed is relative to it.

my $data = $self->build_date($data, $filename);

The variables calculated from the modification time are: weekday, month, monthnum, day, year, hour24, hour, ampm, minute, and second.

my $data = $self->build_is_index($data, $filename);

The variable is_flag is one of the filename is an index file and zero if it is not.

my $data = $self->build_title_from_filename($data, $filename);

The title of the page is derived from the file name by removing the filename extension, removing any leading digits,replacing dashes with spaces, and capitalizing the first character of each word.

$data = $self->build_url($data, $filename);

Build the relative and absolute urls of a web page from a filename.

my $data = $self->internal_fields($data, $filename);

Compute the fields that you must read the file to calculate: title, body, and summary

$str = $self->read_page($filename);

Read a fie into a string. An the entire file is read from a string, there is no line at a time IO. This is because files are typically small and the parsing done is not line oriented.

$self->write_page($filename, $str);

Write a file from a string. An the entire file is read to or written from a string, there is no line at a time IO. This is because files are typically small and the parsing done is not line oriented.

($filenames, $directories) = $self->visit($top_directory);

Return a list of filenames and directories in a directory,

CONFIGURATION ^

The following fields in the configuration file are used in this class and every class based on it:

base_directory

The directory the class is invoked from. This controls which files are returned. The default value is the current directory.

web_extension

The extension used by web pages. This controls which files are returned. The default value is 'html'.

LICENSE ^

Copyright (C) Bernie Simon.

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

AUTHOR ^

Bernie Simon <bernie.simon@gmail.com>

syntax highlighting: