Newcomen

Description A static content generator.
Newcomen > Perl Modules > Newcomen::Formatter::Specification::List
Source

Index


NAME ^

Newcomen::Formatter::Specification::List - A list of formatter backend specifications.

SYNOPSIS ^

use Newcomen::Formatter::Specification::List;

my $formatters = Newcomen::Formatter::Specification::List -> new ();

# Add some formatters:
$formatters -> add ($some_formatter, $another_formatter);

# Get formatter with index 5:
my $formatter = $formatters -> formatter (5);

DESCRIPTION ^

This class manages an ordered list of Newcomen::Formatter::Specification instances. It is used to set the formatters of an Newcomen::Content instance. See the documentation of these two classes for more details. Methods in this class all operate on the formatter specification list. The order of items in the list is important, as formatters will be run in this order.

CLASS METHODS ^

new

my $formatters = Newcomen::Formatter::Specification::List -> new ();

Constructor. Expects no parameters. The formatter specification list will be empty initially.

INSTANCE METHODS ^

Newcomen::Formatter::Specification::List uses an arrayref to store the Newcomen::Formatter::Specification instances as an ordered list. It uses the array methods of Newcomen::Util::Traits, with the following additions:

Please see Newcomen::Util::Traits for a complete list of methods and more details.

add

Toggle source:   add

sub add {

   my $self = shift;

   for my $arg (@_) {

      my $formatters = ref $arg eq 'ARRAY' ? $arg : [$arg];

      for my $formatter (@$formatters) {

         next unless $formatter and (ref $formatter eq '' or ref $formatter eq 'HASH');

         my $name = ref $formatter eq '' ? $formatter : $formatter -> {'name'   };
         my $opts = ref $formatter eq '' ? {}         : $formatter -> {'options'} // {};

         next unless $name and (ref $opts eq 'HASH' or is_a ($opts, 'Newcomen::Data'));

         unless ($self -> find (sub { $_ -> name () eq $name })) {
            my $spec = Newcomen::Formatter::Specification -> new ('name' => $name);
            $spec -> options () -> merge ($opts) if $opts;
            $self -> push ($spec);
         }

      }

   }

}
# Add formatters by name:
$formatters -> add ('MyFormatter', 'MyOtherFormatter');

# This works, too:
$formatters -> add (['MyFormatter', 'MyOtherFormatter']);

# Or supply name and options:
$formatters -> add ({
   'name'    => 'MyFormatter',
   'options' => { 'option' => 'value' },
});

Adds one or more new formatter specifications to the end of the list.

An arbitrary number of parameters may be specified. Each parameter must either be a string specifying the formatter name, a hashref with at least the name key to specify the formatter name and an optional options key to specify formatter options (hashref or Newcomen::Data instance), or an arrayref containing one or more of the aforementioned names or hashrefs. The Newcomen::Formatter::Specification instance will be created automatically from the supplied data. If a formatter specification by that name is already included in the list, this method will not add it again.

The return value of this method is not defined.

SEE ALSO ^

Newcomen::Content, Newcomen::Data, Newcomen::Formatter, Newcomen::Formatter::Specification, Newcomen::Util::Traits

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