view release on metacpan or search on metacpan
README.markdown view on Meta::CPAN
<%
my ($self, $context, $args) = @_;
%>
## $Session
The `$Session` object is an instance of a subclass of [ASP4::SessionStateManager](http://search.cpan.org/perldoc?ASP4::SessionStateManager)
(depending on your website's configuration).
The `$Session` object is a simple blessed hashref and should be used like a hashref.
Examples:
### Set a session variable
$Session->{foo} = "bar";
$Session->{thing} = {
banana => "yellow",
cherry => "red",
inc/Module/Install.pm view on Meta::CPAN
$class =~ s/^\Q$args{prefix}\E:://;
$args{name} ||= $class;
$args{version} ||= $class->VERSION;
unless ( $args{path} ) {
$args{path} = $args{name};
$args{path} =~ s!::!/!g;
}
$args{file} ||= "$args{base}/$args{prefix}/$args{path}.pm";
$args{wrote} = 0;
bless( \%args, $class );
}
sub call {
my ($self, $method) = @_;
my $obj = $self->load($method) or return;
splice(@_, 0, 2, $obj);
goto &{$obj->can($method)};
}
sub load {
inc/Module/Install/Base.pm view on Meta::CPAN
sub new {
my ($class, %args) = @_;
foreach my $method ( qw(call load) ) {
*{"$class\::$method"} = sub {
shift()->_top->$method(@_);
} unless defined &{"$class\::$method"};
}
bless( \%args, $class );
}
#line 61
sub AUTOLOAD {
my $self = shift;
local $@;
my $autoload = eval { $self->_top->autoload } or return;
goto &$autoload;
}
inc/Module/Install/Base.pm view on Meta::CPAN
sub is_admin {
$_[0]->admin->VERSION;
}
sub DESTROY {}
package Module::Install::Base::FakeAdmin;
my $Fake;
sub new { $Fake ||= bless(\@_, $_[0]) }
sub AUTOLOAD {}
sub DESTROY {}
# Restore warning handler
BEGIN {
$SIG{__WARN__} = $SIG{__WARN__}->();
}
inc/Module/Install/Metadata.pm view on Meta::CPAN
sub version_from {
require ExtUtils::MM_Unix;
my ( $self, $file ) = @_;
$self->version( ExtUtils::MM_Unix->parse_version($file) );
}
sub abstract_from {
require ExtUtils::MM_Unix;
my ( $self, $file ) = @_;
$self->abstract(
bless(
{ DISTNAME => $self->name },
'ExtUtils::MM_Unix'
)->parse_abstract($file)
);
}
# Add both distribution and module name
sub name_from {
my ($self, $file) = @_;
if (
lib/ASP4.pm view on Meta::CPAN
<%
my ($self, $context, $args) = @_;
%>
=head2 $Session
The C<$Session> object is an instance of a subclass of L<ASP4::SessionStateManager>
(depending on your website's configuration).
The C<$Session> object is a simple blessed hashref and should be used like a hashref.
Examples:
=head3 Set a session variable
$Session->{foo} = "bar";
$Session->{thing} = {
banana => "yellow",
cherry => "red",
lib/ASP4/API.pm view on Meta::CPAN
$test_data = ASP4::Test::Fixtures->new(
properties_file => $config->web->application_root . '/etc/test_fixtures.yaml'
);
}# end if()
# Our diagnostic messages:
my $properties = Data::Properties::YAML->new(
properties_file => $config->web->application_root . '/etc/properties.yaml'
) if -f $config->web->application_root . '/etc/properties.yaml';
return bless {
test_fixtures => $test_data,
properties => $properties,
ua => ASP4::UserAgent->new(),
config => $config,
}, $class;
}# end new()
*init = \&new;
sub test_fixtures { shift->{test_fixtures} }
lib/ASP4/ConfigNode.pm view on Meta::CPAN
use strict;
use warnings 'all';
use Carp 'confess';
sub new
{
my ($class, $ref) = @_;
local $SIG{__DIE__} = \&Carp::confess;
my $s = bless $ref, $class;
$s->init_keys();
$s;
}# end new()
sub init_keys
{
my $s = shift;
foreach my $key ( grep { ref($s->{$_}) eq 'HASH' } keys(%$s) )
lib/ASP4/ConfigParser.pm view on Meta::CPAN
use strict;
use warnings 'all';
use ASP4::Config;
sub new
{
my ($class) = @_;
return bless { }, $class;
}# end new()
sub parse
{
my ($s, $doc, $root) = @_;
my $config = ASP4::Config->new( $doc, $root );
# Now do any post-processing:
lib/ASP4/ConfigPostProcessor.pm view on Meta::CPAN
ASP4::ConfigPostProcessor;
use strict;
use warnings 'all';
sub new
{
my ($class, %args) = @_;
return bless \%args, $class;
}# end new()
sub post_process($$);
1;# return true:
lib/ASP4/Error.pm view on Meta::CPAN
form_data => encode_json($Form) || "{}",
session_data => eval { encode_json(\%session_data) } || "{}",
http_referer => $ENV{HTTP_REFERER},
user_agent => $ENV{HTTP_USER_AGENT},
http_code => ($Response->Status =~ m{^(\d+)})[0],
remote_addr => $ENV{REMOTE_ADDR} || '127.0.0.1',
# Allow overrides:
%args
);
return bless \%info, $class;
}# end new()
sub domain { $_[0]->{domain} }
sub request_uri { $_[0]->{request_uri} }
sub file { $_[0]->{file} }
sub line { $_[0]->{line} }
sub message { $_[0]->{message} }
sub stacktrace { $_[0]->{stacktrace} }
sub code { $_[0]->{code} }
lib/ASP4/FileUpload.pm view on Meta::CPAN
{
confess "Required param '$_' was not provided"
unless $args{$_};
}# end foreach()
$args{UploadedFileName} = $args{FileName};
($args{FileName}) = $args{FileName} =~ m{[/\\]?([^/\\]+)$};
($args{FileExtension}) = $args{FileName} =~ m/([^\.]+)$/;
$args{FileSize} = (stat($args{FileHandle}))[7];
return bless \%args, $class;
}# end new()
# Public readonly properties:
sub ContentType { shift->{ContentType} }
sub FileName { shift->{FileName} }
sub UploadedFileName { shift->{UploadedFileName} }
sub FileExtension { shift->{FileExtension} }
sub FileSize { shift->{FileSize} }
lib/ASP4/FilterResolver.pm view on Meta::CPAN
use strict;
use warnings 'all';
my %FilterCache = ( );
sub new
{
my ($class, %args) = @_;
return bless \%args, $class;
}# end new()
sub context { ASP4::HTTPContext->current }
sub resolve_request_filters
{
my ($s, $uri) = @_;
lib/ASP4/HTTPContext.pm view on Meta::CPAN
use ASP4::OutBuffer;
use ASP4::SessionStateManager::NonPersisted;
use Carp 'confess';
use vars '$_instance';
sub new
{
my ($class, %args) = @_;
my $s = bless {
config => ASP4::ConfigLoader->load,
buffer => [ ASP4::OutBuffer->new ],
stash => { },
headers_out => HTTP::Headers->new(),
is_subrequest => $args{is_subrequest},
}, $class;
$s->config->_init_inc();
my $web = $s->config->web;
$s->config->load_class( $web->handler_resolver );
lib/ASP4/HTTPHandler.pm view on Meta::CPAN
$Config $Form
$Stash
)
}
use vars __PACKAGE__->VARS;
}
sub new {
my ($class, %args) = @_;
return bless \%args, $class;
}
sub before_run { 1; }
sub after_run { }
sub request { $Request }
sub response { $Response }
sub session { $Session }
sub stash { $Stash }
sub server { $Server }
lib/ASP4/HandlerResolver.pm view on Meta::CPAN
use ASP4::PageLoader;
use File::stat;
my %HandlerCache = ( );
my %FileTimes = ( );
sub new
{
my ($class, %args) = @_;
return bless \%args, $class;
}# end new()
sub context { ASP4::HTTPContext->current }
sub resolve_request_handler
{
my ($s, $uri) = @_;
lib/ASP4/HandlerRunner.pm view on Meta::CPAN
ASP4::HandlerRunner;
use strict;
use warnings 'all';
sub new
{
my ($class, %args) = @_;
return bless \%args, $class;
}# end new()
sub context { ASP4::HTTPContext->current }
sub run_handler
{
my ($s, $handler_class, $args) = @_;
lib/ASP4/Mock/ClientSocket.pm view on Meta::CPAN
package ASP4::Mock::ClientSocket;
use strict;
use warnings 'all';
sub new {
return bless {
on_close => sub { },
}, shift;
}
sub on_close { my $s = shift; $s->{on_close} = shift }
sub close { shift->{on_close}->( ) }
1;# return true:
=pod
lib/ASP4/Mock/Connection.pm view on Meta::CPAN
package ASP4::Mock::Connection;
use strict;
use warnings 'all';
use ASP4::Mock::ClientSocket;
sub new {
my $s = bless {
aborted => 0,
client_socket => ASP4::Mock::ClientSocket->new()
}, shift;
$s->{client_socket}->on_close(sub {
$s->{aborted} = 0;
});
return $s;
}
lib/ASP4/Mock/Pool.pm view on Meta::CPAN
package ASP4::Mock::Pool;
use strict;
use warnings 'all';
sub new { return bless { cleanup_handlers => [ ] }, shift }
sub call_cleanup_handlers {
my $s = shift;
map { $_->( ) } @{ $s->{cleanup_handlers} }
}
sub cleanup_register {
my ($s, $handler, $args) = @_;
push @{ $s->{cleanup_handlers} }, sub { $handler->( $args ) };
}
lib/ASP4/Mock/RequestRec.pm view on Meta::CPAN
use ASP4::Mock::Pool;
use ASP4::Mock::Connection;
use ASP4::ConfigLoader;
use Scalar::Util 'weaken';
sub new
{
my ($class, %args) = @_;
my $s = bless {
status => 200,
content_type => 'text/plain',
buffer => '',
document_root => ASP4::ConfigLoader->load()->web->www_root,
headers_in => { },
headers_out => { },
uri => $args{uri} || $ENV{REQUEST_URI},
args => $args{args} || $ENV{QUERY_STRING},
pnotes => { },
method => $args{method},
lib/ASP4/OutBuffer.pm view on Meta::CPAN
package
ASP4::OutBuffer;
use strict;
use warnings 'all';
sub new
{
return bless { data => '' }, shift;
}# end new()
sub add
{
my ($s, $str) = @_;
return unless defined($str);
$s->{data} .= $str;
return;
}# end add()
lib/ASP4/Page.pm view on Meta::CPAN
use base 'ASP4::HTTPHandler';
use Carp 'confess';
use ASP4::HTTPContext;
use ASP4::PageParser;
sub new
{
my ($class, %args) = @_;
my $s = bless {
masterpage => undef,
package => undef,
filename => undef,
compiled_as => undef,
script_name => $args{script_name} || undef,
%args
}, $class;
$s->_init();
lib/ASP4/PageParser.pm view on Meta::CPAN
use warnings 'all';
use ASP4::ConfigLoader;
use ASP4::Page;
use ASP4::MasterPage;
sub new
{
my ($class, %args) = @_;
my $s = bless {
script_name => $args{script_name},
filename => undef,
package => undef,
compiled_as => undef,
base_class => undef,
source_code => \"",
}, $class;
$s->_init();
return $s;
lib/ASP4/Request.pm view on Meta::CPAN
use strict;
use warnings 'all';
sub new
{
my ($class, %args) = @_;
my $cgi = $class->context->cgi;
my $s = bless {
%args,
form => {
(
map {
# CGI->Vars joins multi-value params with a null byte. Which sucks.
# To avoid that behavior, we do this instead:
my @val = map { $cgi->unescape( $_ ) } ( $cgi->param($_) );
$cgi->unescape($_) => scalar(@val) > 1 ? \@val : shift(@val)
} $cgi->param
),
lib/ASP4/Response.pm view on Meta::CPAN
use strict;
use warnings 'all';
use HTTP::Date qw( time2str );
use ASP4::HTTPContext;
use ASP4::Mock::RequestRec;
sub new
{
my $s = bless {
_status => 200,
_expires => 0,
_content_type => 'text/html',
_expires_absolute => time2str( time() ),
}, shift;
$s->Status( $s->Status );
$s->Expires( $s->Expires );
$s->ContentType( $s->ContentType );
return $s;
lib/ASP4/Server.pm view on Meta::CPAN
package ASP4::Server;
use strict;
use warnings 'all';
use ASP4::HTTPContext;
use ASP4::Error;
use Mail::Sendmail;
sub new
{
return bless { }, shift;
}# end new()
sub context { ASP4::HTTPContext->current }
sub URLEncode
{
ASP4::HTTPContext->current->cgi->escape( $_[1] );
}# end URLEncode()
lib/ASP4/SessionStateManager.pm view on Meta::CPAN
use Time::HiRes 'gettimeofday';
use Digest::MD5 'md5_hex';
use Storable qw( freeze thaw );
use Scalar::Util 'weaken';
use ASP4::ConfigLoader;
sub new
{
my ($class, $r) = @_;
my $s = bless { }, $class;
my $conn = context()->config->data_connections->session;
local $^W = 0;
$class->set_db('Session',
$conn->dsn,
$conn->username,
$conn->password
);
my $id = $s->parse_session_id();
lib/ASP4/SessionStateManager.pm view on Meta::CPAN
ASP4::SessionStateManager - Per-user state persistence
=head1 SYNOPSIS
You've seen this page <%= $Session->{counter}++ %> times before.
=head1 DESCRIPTION
Web applications require session state management - and the simpler, the better.
C<ASP4::SessionStateManager> is a simple blessed hash. When it goes out of scope,
it is saved to the database (or whatever).
If no changes were made to the session, it is not saved.
=head1 PUBLIC PROPERTIES
=head2 is_read_only( 1:0 )
Starting with version 1.044, setting this property to a true value will prevent
any changes made to the contents of the session during the current request from
lib/ASP4/SessionStateManager/InMemory.pm view on Meta::CPAN
use warnings 'all';
use base 'ASP4::SessionStateManager';
my $cache = {};
sub new
{
my ($class, $r) = @_;
my $id = $class->parse_session_id();
my $s = bless {SessionID => $id}, $class;
my $conn = ASP4::ConfigLoader->load->data_connections->session;
unless( $id && $s->verify_session_id( $id, $conn->session_timeout ) )
{
$s->{SessionID} = $s->new_session_id();
$s->write_session_cookie($r);
return $s->create( $s->{SessionID} );
}# end unless()
return $s->retrieve( $id );
}# end new()
lib/ASP4/SessionStateManager/Memcached.pm view on Meta::CPAN
use warnings 'all';
use base 'ASP4::SessionStateManager';
use Cache::Memcached;
use JSON::XS;
my $memd;
sub new
{
my ($class, $r) = @_;
my $s = bless { }, $class;
my $conn = ASP4::ConfigLoader->load->data_connections->session;
$memd = Cache::Memcached->new({
servers => [ $conn->dsn ]
});
my $id = $s->parse_session_id();
unless( $id && $s->verify_session_id( $id, $conn->session_timeout ) )
{
$s->{__ttl} = $conn->session_timeout;
$s->{SessionID} = $s->new_session_id();
lib/ASP4/SessionStateManager/Memcached.pm view on Meta::CPAN
return $s->retrieve( $id );
}# end new()
sub verify_session_id
{
my ($s, $id) = @_;
my $ref = $memd->get( $id )
or return;
$s = bless decode_json($ref), ref($s) ? ref($s) : $s;
}# end verify_session_id()
*retrieve = \&verify_session_id;
sub create
{
my ($s, $id) = @_;
$s->save();
return $s;
lib/ASP4/SessionStateManager/NonPersisted.pm view on Meta::CPAN
package
ASP4::SessionStateManager::NonPersisted;
use strict;
use warnings 'all';
use base 'ASP4::SessionStateManager';
sub new
{
return bless { }, shift;
}# end new()
*create = *retrieve = \&new;
sub save { 1 }
1;# return true: