App-AutoCRUD

 view release on metacpan or  search on metacpan

lib/App/AutoCRUD/Context.pm  view on Meta::CPAN

package App::AutoCRUD::Context;

use 5.010;
use strict;
use warnings;

use Moose;
use MooseX::SemiAffordanceAccessor; # writer methods as "set_*"
use Carp;
use Scalar::Does qw/does/;
use Encode       ();

use namespace::clean -except => 'meta';


has 'app'          => (is => 'ro', isa => 'App::AutoCRUD', required => 1,
                       handles => [qw/config dir/]);
has 'req'          => (is => 'ro', isa => 'Plack::Request', required => 1,
                       handles => [qw/logger/]);
has 'req_data'     => (is => 'ro', isa => 'HashRef',
                       builder => '_req_data', lazy => 1, init_arg => undef);
has 'base'         => (is => 'ro', isa => 'Str',
                       builder => '_base', lazy => 1, init_arg => undef);
has 'path'         => (is => 'rw', isa => 'Str',
                       builder => '_path', lazy => 1);
has 'template'     => (is => 'rw', isa => 'Str');
has 'view'         => (is => 'rw', isa => 'App::AutoCRUD::View',
                       builder => '_view', lazy => 1);
has 'process_time' => (is => 'rw', isa => 'Num');

has 'datasource'   => (is => 'rw', isa => 'App::AutoCRUD::DataSource',
                       handles => [qw/dbh schema/]);
has 'title'        => (is => 'rw', isa => 'Str',
                       builder => '_title', lazy => 1);


sub _view {
  my $self = shift;

  # default view, if no specific view was required from the URL
  return $self->app->find_class("View::TT")->new;
}


sub _req_data {
  my $self = shift;

  require CGI::Expand;
  my $req_data = CGI::Expand->expand_cgi($self->req);
  _decode_utf8($req_data);
  return $req_data;
}

sub _base {
  my $self = shift;

  my $base = $self->req->base->as_string;
  $base .= "/" unless $base =~ m[/$]; # force trailing slash
  return $base
}

sub _path {
  my $self = shift;

  return $self->req->path;
}

sub _title {
  my $self = shift;

  my $title      = $self->app->name;
  my $datasource = $self->datasource;
  $title        .= "-" . $datasource->name if $datasource;

  return $title;
}


sub extract_path_segments {
  my ($self, $n_segments) = @_;

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.275 second using v1.00-cache-2.02-grep-82fe00e-cpan-72ae3ad1e6da )