Newcomen

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

Index


NAME ^

Newcomen::Crawler - Manages the sources of an Newcomen project.

SYNOPSIS ^

use Newcomen::Crawler;

my $crawler = Newcomen::Crawler -> new ();

# Add a source item:
$crawler -> add ($source);

# Get a source item:
my $source = $crawler -> source ($source_id);

# Iterate over all sources:
for my $source ($crawler -> sources ()) {
   # do something...
}

DESCRIPTION ^

Newcomen::Crawler is a container for the source items (Newcomen::Source instances) of the Newcomen project. See the developer section in Newcomen::Manual for a description of how Newcomen works and how the crawler fits in.

Note: Despite its name this class can not be used to gather the source items (e.g. from the file system or a database). It is just a container class. Plugins may - for example - use the role Newcomen::Role::Crawler::Filesystem to get sources from the file system.

Plugins may use Newcomen::Role::Attribute::Crawler to access the main crawler instance.

CLASS METHODS ^

new

my $crawler = Newcomen::Crawler -> new ();

Constructor. Expects no parameters, the sources list will be empty initially.

INSTANCE METHODS ^

Newcomen::Crawler uses a hashref to store the source items, with the source IDs as keys, and the source instances as values. It uses the hash methods of Newcomen::Util::Traits, with the following exceptions and additions:

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

add

Toggle source:   add

sub add {

   my $self = shift;
   my $src  = shift;

   confess 'Source ID not unique: ' . $src -> id () if $self -> exists ($src -> id ());

   $self -> _set ($src -> id (), $src);

}
$crawler -> add ($source);

This method adds a source (an Newcomen::Source instance) to the crawler. The source instance may then be accessed by its source ID. The ID must be unique, trying to add an item with an ID that already exists in the crawler's list will cause an error (the method will die()).

SEE ALSO ^

Newcomen::Manual, Newcomen::Role::Attribute::Crawler, Newcomen::Role::Crawler::Filesystem, Newcomen::Source, 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/>.