Bryar::Config - A set of configuration settings for Bryar


Bryar documentation Contained in the Bryar distribution.

Index


Code Index:

NAME

Top

Bryar::Config - A set of configuration settings for Bryar

SYNOPSIS

Top

	Bryar::Config->new(...);
	Bryar::Config->load(...);

DESCRIPTION

Top

This encapsulates a Bryar configuration. It can be used to load a new configuration from a file, or provide a reasonable set of defaults.

METHODS

Top

new

    Bryar::Config->new(...)

Creates a new Bryar configuration instance.

load

    $self->load($file)

Load the configuration file from somewhere and return the arguments as a hash.

renderer

	$self->renderer();    # Get renderer
	$self->renderer(...); # Set renderer

The class used to render this blog; defaults to "Bryar::Renderer::TT", the Template Toolkit renderer.

frontend

	$self->frontend();    # Get frontend
	$self->frontend(...); # Set frontend

The class used to handle input and output from the blog; defaults to Bryar::Frontend::CGI if run via the CGI, Bryar::Frontend::mod_perl from inside Apache.

collector

	$self->collector();    # Get collector
	$self->collector(...); # Set collector

The class used to select which documents to output. You probably don't want to mess with this.

source

	$self->source();    # Get source
	$self->source(...); # Set source

The class which finds the blog posts. Defaults to Bryar::DataSource::FlatFile, the blosxom-compatible data source.

cache

	$self->cache();    # Get cache object
	$self->cache(new Cache::FileCache()); # Set cache object

An instance of a Cache::Cache subclass which will be used to cache the formatted pages.

datadir

	$self->datadir();    # Get datadir
	$self->datadir(...); # Set datadir

Where the templates (and in the case of the flat-file data source, the blog posts) live.

name

	$self->name();    # Get name

The name of this blog.

description

	$self->description();    # Get description

A description for the blog.

depth

	$self->depth();    # Get depth
	$self->depth(...); # Set depth

How far to recurse into sub-blogs. Default is 1, stay in the current directory.

email

    $self->email();     # Get email

Get the owner's email address. This is used for spam reporting.

recent

    $self->recent();    # Get recent
    $self->recent(...); # Set recent

The number of entries to display if there are no other parameters given. Defaults to 20 entries.

baseurl

	$self->baseurl();    # Get baseurl

The base URL of this blog. (Needed for setting up links to archived posts, etc.)

LICENSE

Top

This module is free software, and may be distributed under the same terms as Perl itself.

AUTHOR

Top

Copyright (C) 2003, Simon Cozens simon@kasei.com

some parts Copyright 2007 David Cantrell david@cantrell.org.uk


Bryar documentation Contained in the Bryar distribution.
package Bryar::Config;
use UNIVERSAL::require;
use 5.006;
use strict;
use warnings;
use Carp;
our $VERSION = '1.1';

our %default_args = (
        source => "Bryar::DataSource::FlatFile",
        name => "My web log",
        description => "Put a better description here",
        baseurl =>  "",
        datadir => ".",
        email => 'someone@example.com',
        depth => 1,
        recent => 20,
        renderer => "Bryar::Renderer::TT",
        collector => "Bryar::Collector",
        frontend => ((exists $ENV{GATEWAY_INTERFACE} and 
                      $ENV{'GATEWAY_INTERFACE'} =~ /^CGI-Perl\//)
                    ? "Bryar::Frontend::Mod_perl"
                    : "Bryar::Frontend::CGI")
);

sub new {
    my $class = shift;
    my %args = (%default_args, @_); # This does need to happen in stages
    my $self = bless { %args, %_ }, $class;
    # Because setting datadir above may affect where the config file is.

    %args = (%args, $self->load($args{config} || "bryar.conf"));
    @{$self}{keys %args} = values %args;

    foreach my $module (qw(renderer source collector frontend)) {
        $self->$module->require or die $@;
        $self->$module($self->$module->new(config => $self))
            if $self->$module->can('new') or ref $self->$module;
    }

    return $self;
}

sub load {
    my ($self, $file) = @_;
    my %args;
    my $datadir = $self->{datadir};
    if (!-r $file) {
        if (-r "$datadir/$file") { $file = "$datadir/$file"; }
        else                     { return () }
    }
    open(my $config, '<:utf8', $file) or return ();
    while (<$config>) {
        chomp;
        next if /^#/ or /^$/;
        my ($k, $v) = split /\s*:\s*/, $_, 2;
        $args{$k} = $v;
    }
    close $config;
    return %args;
}

sub renderer {
    my $self = shift;
    if (@_) { $self->{renderer} = shift };

    return $self->{renderer};
}


sub frontend {
    my $self = shift;
    if (@_) { $self->{frontend} = shift };

    return $self->{frontend};
}

sub collector {
    my $self = shift;
    if (@_) { $self->{collector} = shift };

    return $self->{collector};
}

sub source {
    my $self = shift;
    if (@_) { $self->{source} = shift };

    return $self->{source};
}


sub cache {
    my $self = shift;
    if (@_) { $self->{cache} = shift };

    return $self->{cache};
}


sub datadir {
    my $self = shift;
    if (@_) { $self->{datadir} = shift};

    return $self->{datadir};
}


sub name {
    my $self = shift;
    return $self->{name};
}

sub description {
    my $self = shift;
    return $self->{description};
}


sub depth {
    my $self = shift;
    if (@_) { $self->{depth} = shift };

    return $self->{depth};
}

sub email {
    my $self = shift;
    return $self->{email};
}

sub recent {
    my $self = shift;
    if (@_) { $self->{recent} = shift };

    return $self->{recent};
}

sub baseurl {
    my $self = shift;
    return $self->{baseurl};
}


1;