Rhetoric

 view release on metacpan or  search on metacpan

lib/Rhetoric.pm  view on Meta::CPAN

  'theme.base'          => './share/theme',

  'login'               => 'admin',
  'password'            => 'admin',

  'storage'             => 'File',                # Rhetoric::Storage::____
  'storage.file.path'   => '.',
  # TODO
  'storage.couchdb.url'    => undef,              # URL for CouchDB database
  # TODO
  'storage.mysql.connect'  => undef,              # connect string suitable for DBI->connect
  'storage.mysql.user'     => undef,
  'storage.mysql.password' => undef,

  # just for continuity
  docroot => 'share',
);

sub continue {
  my $app = shift;
  $app->next::method(
    docroot => $CONFIG{'docroot'}, 
    staticp => sub { $_[0]->url =~ m/\.(jpg|jpeg|gif|png|css|ico|js|swf)$/ },
    @_
  );
}

# service() is run on every request (just like in Camping).
sub service {
  my ($class, $c, @args) = @_;
  $c->view = $c->state->{theme} // $CONFIG{theme};
  my $v = $c->v;
  my $s = $c->env->{storage} = storage($CONFIG{storage});
  H->bless($v);
  H->bless($c->input);
  H->bless($c->env);
  $v->{title}        = $s->meta('title');
  $v->{subtitle}     = $s->meta('subtitle');
  $v->{copy}         = $s->meta('copy');
  $v->{menu}         = $s->menu;
  $v->{request_path} = $c->env->{REQUEST_PATH};
  $v->{time_format}  = $CONFIG{time_format};
  $v->{hostname}     = $CONFIG{hostname} // $c->env->{HTTP_HOST};
  $v->{state}        = $c->state; # XXX - Should Squatting be doing this automatically?

  # hack to help rh-export
  if ($c->state->{mock_request}) {
    # the RIGHT THING(tm) would be to change how we store menu information.
    # I suppose I need to support perl expressions in there instead of
    # just strings.
    # FIXME
    for my $menu (@{$v->{menu}}) {
      my $href = $menu->url;
      if (($href !~ qr{^https?:}) && ($href !~ qr{\.html$}) && ($href ne '/')) {
        $href .= ".html";
        $menu->url($href);
      }
    }
  }

  if (exists $CONFIG{relocated}) {
    for (@{ $v->menu }) {
      $_->url($CONFIG{relocated} . $_->url);
    }
    $v->{relocated} = $CONFIG{relocated};
  }
  for my $position ($s->widgets->positions) {
    $v->{widgets}{$position} = [ $s->widgets->content_for($position, $c, @args) ];
  }
  $class->next::method($c, @args);
}

# initialize app
sub init {
  my ($class) = @_;

  # TODO - Make absolutely sure the Page controller is at $C[-1].
  if ($Rhetoric::Controllers::C[-1]->name ne 'Page') {
    # find index of Page controller
    # splice it out
    # push it back on to the end
  }

  # view initialization
  Rhetoric::Views::init();

  $class->next::method();
}

# Return an object that handles the storage for blog data based on
# what $CONFIG{storage} dictates.
sub storage {
  no strict 'refs';
  my $impl    = shift;
  my $path    = "Rhetoric/Storage/$impl.pm";
  my $package = "Rhetoric::Storage::$impl";
  require($path); # let it die if it fails.

  # the stuff that's ALWAYS in the filesystem (besides widgets)
  # menus and pages might get split out later
  my $meta = $Rhetoric::Meta::meta;

  # where posts and comments are stored
  my $storage = ${"${package}::storage"};
  $storage->init(\%CONFIG);

  # widgets
  my $widgets = $Rhetoric::Widgets::widgets;
  $widgets->init(\%CONFIG);

  my $blog = H->new({
    base    => $CONFIG{base},
    widgets => $widgets,
    %$meta,
    %$storage,
  });
}

#_____________________________________________________________________________
package Rhetoric::Controllers;
use common::sense;
use aliased 'Squatting::H';
use Method::Signatures::Simple;
use Rhetoric::Helpers ':all';
use Data::Dump 'pp';



( run in 0.796 second using v1.01-cache-2.11-cpan-5511b514fd6 )