Newcomen

Description A static content generator.
Newcomen > Perl Modules > Newcomen::Writer
Source

Index


NAME ^

Newcomen::Writer - Writer frontend.

SYNOPSIS ^

use Newcomen::Writer;

my $writer = Newcomen::Writer -> new ();

$writer -> write_page ($page);

DESCRIPTION ^

Newcomen::Writer is the frontend for the page writing modules. The actual writing (if any, the method to store a page depends on the backend) will be done by backends. The writer backend to use and its options are set on a per-page basis (see Newcomen::Page).

Plugins may use Newcomen::Role::Attribute::Writer to access the main writer instance, but usually this should not be necessary.

OPTIONS ^

{
   'writer'        => {
      'output_dir' => undef,
      'override'   => undef,
   },
}

These default options may be used by backends unless overridden by backend specific options. output_dir specifies the output directory, relative to the project's root directory. override may be set to a true value if writer backends should override existing files. See the individual backends for more options.

Note: It is up to the backends to respect these options. See the appropriate backend documentation to find out if these options are used or not.

CLASS METHODS ^

new

my $writer = Newcomen::Writer -> new ();

Constructor. Expects no parameters.

INSTANCE METHODS ^

Writing

write_page

Toggle source:   write_page

sub write_page {

   my $self = shift;
   my $page = shift;

   return unless defined $page -> writer ();

   my $name = $page -> writer () -> name ();
   my $full = "Newcomen::Writer::$name";
   confess "No such writer: $name" unless $self -> backend ($full);

   $self -> backend ($full) -> write ($page, $page -> writer () -> options ());

}
$writer -> write_page ($page);

Expects a single Newcomen::Page instance as parameter. If there is a writer backend set for the page, the backend will be called to write it. What exactly this means depends on the backend, see the individual backends for details. The return value of this method is not specified. Details and backend options may differ for different backends, see the appropriate documentation for details. Backend names must be module basenames only (i.e. without the 'Newcomen::Writer::' prefix), and names are case sensitive. The backend must exist, else this method will die().

Backends

The methods backend(), backend_exists() and backends() are available to access the writer backends, though usually this should not be necessary. For a description of these methods please see Newcomen::Role::Frontend.

MISCELLANEOUS ^

Backends must use Newcomen::Writer::Backend as their base class. They must be placed in the Newcomen::Writer namespace, and implement a _do_write() method. For more details, see Newcomen::Writer::Backend.

SEE ALSO ^

Newcomen::Page, Newcomen::Role::Attribute::Writer, Newcomen::Role::Frontend, Newcomen::Writer::Backend

VERSION ^

This is version 2014052501.

AUTHOR ^

Stefan Goebel - newcomen {at} subtype {dot} de

COPYRIGHT AND LICENSE ^

Copyright 2013-2014 Stefan Goebel.

This file is part of Newcomen.

Newcomen is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the license, or (at your option) any later version.

Newcomen is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Newcomen. If not, see <http://www.gnu.org/licenses/>.