Newcomen

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

Index


NAME ^

Newcomen::Writer::Backend - Base class for writer backends.

SYNOPSIS ^

package Newcomen::Writer::MyBackend;

use namespace::autoclean;
use Moose;

extends 'Newcomen::Writer::Backend';

override '_do_write' => sub {

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

   # Write page...

};

__PACKAGE__ -> meta () -> make_immutable ();

1;

DESCRIPTION ^

This is the base class to be extended by writer backends. It does not define any attributes. It does define the methods write() and _do_write(). write() will call the _do_write() method, which has to be overridden by the actual backend implementation (see SYNOPSIS). The _do_write() method of the base class will simply die()!

CLASS METHODS ^

new

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

Constructor, expects no parameters. new() will be called once for every (!) backend found. A backend does not have to be actually used to be instantiated! If it is actually used, write() will be called. The one backend instance will be used for writing all pages.

INSTANCE METHODS ^

write

Toggle source:   write

sub write {

   my $self = shift;
   my $page = shift;
   my $opts = shift // Newcomen::Data -> new ();

   confess 'Usage: write($page,$options)' unless
      is_a ($page, 'Newcomen::Page') and is_a ($opts, 'Newcomen::Data') and not @_;

   $self -> _do_write ($page, $opts);

}
$backend -> write ($page, $backend_options);

The write() method of a backend will be called when a page should be written. Its return value is not defined. The page to be written (an Newcomen::Page instance) must be passed as first parameter. The backend options must be passed as second parameter. This must be an Newcomen::Data instance or undef. The write() method must not be overridden by a backend implementation!

MISCELLANEOUS ^

_do_write

Toggle source:   _do_write

sub _do_write { confess '_do_write() not implemented by backend' }

The actual backends must implement a _do_write() method, _do_write() of this base class will die(). The page to be written (an Newcomen::Page instance) will be the first parameter of this method, the Newcomen::Data instance containing the options (or a newly created empty one, if no options were supplied) will be the second parameter. _do_render() has to do whatever is needed to write the page content, its return value will be ignored.

SEE ALSO ^

Newcomen::Data, Newcomen::Page, Newcomen::Writer

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/>.