ASP4

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

2012-02-02    1.078
  - Fixed installation problem that came up in v1.075 
    (compilation root was missing leading forward slash on non-windows systems).

2012-02-01    1.077
  - Loath to add a mime-types-all-knowing dependency, we have a small list of
    common mime-types (html, css, js, etc).
  - Added mime for html and svg.

2012-02-01    1.076
  - Now, the 'content-type' header is set correctly for ASP4::UserAgent responses.
  - Works correctly under ASP4::PSGI (images, css, javascript all show up).

2012-02-01    1.075
  - Now, works on Windows!
  - eric.hayes++

2012-01-30    1.074
  - Explicit calls to $Session->save() are no longer necessary.

2012-01-23    1.073

Changes  view on Meta::CPAN

  - Update documentation to reflect preference change from app::* to App::db::*
    root namespace for database classes.

2011-08-14    1.051
[Bug Fixes]
  - 'Redirect Loop' fixed!  Under mod_perl, $context->send_headers() was not 
    called for non-200 http responses.
    Now it is.
    This means that if you had `return $Response->Redirect("/foo/")` in a RequestFilter
    you may have gotten a "redirect loop" because although the '301 Moved' status
    was set, the `location: /foo/` header was *not* set.  This would result in
    a redirect loop.

2011-07-11    v1.050
[Bug Fixes]
  - v1.049 Caused script execution to cease after any $Response->Include or ssi
    include finished.
  - Upgrade required if you know what's good for you.


2011-07-09    v1.049

Changes  view on Meta::CPAN

[Bug Fixes]
  - $Response->Expires("30M") wasn't documented.  Now it is.
  - $Response->Expires wasn't working properly.  Now it is. (Always ended up with pre-epoch expiration times).

2011-05-03    v1.046
[Bug Fixes]
  - $Response->Redirect(...) wasn't returning '301' - now it does.

2011-05-03    v1.045
[Bug Fixes]
  - Actually it turned out that setting $Session->is_read_only(1) *DID* prevent
    $Session->save() from working.  This is now fixed to match the documentation.

2011-05-01    v1.044

[Bug Fixes]
  - ASP4::ModPerl now does the Right Thing when a non-200 response is encountered.
    - 500 response does not result in an "encoding error" in firefox.
    - 200 (or 0 response) does the right thing.
    - non-200 (and non-500) response does the right thing (eg: 401)
  - ASP4::SessionStateManager now checks $s->is_changed *before* checking $s->{__lastMod} date

Changes  view on Meta::CPAN

    are cached - now not only by URL but also by $ENV{DOCUMENT_ROOT}.

2010-05-20    v1.032
  - Fixed several issues related to running multiple web applications under different
    VirtualHosts on the same server.

2010-05-19    v1.031
  - Migrated from Ima::DBI to Ima::DBI::Contextual.

2010-05-18    v1.030
  - $ENV{HTTP_HOST} is set to $r->hostname or $ENV{DOCUMENT_ROOT} in ASP4::ModPerl and ASP4::UserAgent, respectively.

2010-04-18    v1.029
  - The document root was not always set properly in some very, very strange
    circumstances.
  - Upgrade recommended.

2010-04-18    v1.028
  - $Request->Reroute($uri) no longer changes $ENV{REQUEST_URI} to $uri.

2010-04-15    v1.027
  - ASP4::Request was not properly URLDecoding parameters.  Now it does.

2010-04-13    v1.026

Changes  view on Meta::CPAN

    active sessions.

2010-03-08    v1.021
  - Removed a warning that popped up now and then about the use of an uninitialized value.
  - Added a more informative "Yay you're finished!" message after running asphelper.

2010-03-04    v1.020
  - Now asphelper will output sbin/ddl.sql, which contains the structure of the 
    asp_sessions database table.  This is a handy place to start describing the
    database structure of a web application.
  - If $Config->web->data_connections->session->session_timeout is set to '*' then
    the session lasts as long as the browser keeps the cookie around.
  - 20% performance increase by using Cwd::fastcwd() instead of Cwd::cwd() and a
    few other minor tweaks.

2010-03-02    v1.019
  - Fixed a bug in asphelper that caused some problems creating a skeleton website.

2010-03-01    v1.018
  - Updated asphelper script so that the POD on CPAN is not contaminated with POD
    from within one of the modules that asphelper generates.

Changes  view on Meta::CPAN

    Class::DBI::Lite is installed.

2010-03-01    v1.017
  - Updated asphelper script to only accept options on the command-line, like "normal" scripts.

2010-02-28    v1.016
  - A vestigial "use encoding 'utf8'" was removed from ASP4::Server.
  - It was causing Apache to segfault on ubuntu 9.10.

2010-02-19    v1.015
  - Hostnames like http://myapplication/ were not setting session cookies properly.
  - $Config->data_connections->session->cookie_domain should set to "*" in these cases.
  - $Response->SetCookie accepts the "*" value for domain also.
  - The result is that no "domain=xyz" attribute is given to these cookies.

2010-02-18    v1.014
  - $Response->ContentType now functions correctly.
  - Upgrade mandatory!

2010-02-18    v1.013
  - ASP4::HandlerResolver was not properly remembering timestamps on handler files.
    This resulted in unnecessary reloads of handlers that had not been changed.

Changes  view on Meta::CPAN


2010-02-10    v1.010
  ! UPGRADE *SERIOUSLY* RECOMMENDED !
  - In an environment with multiple VirtualHosts running ASP4 web applications,
    ASP4::HandlerResolver's %HandlerCache and %FileTimes hashes were shared between
    all VirtualHosts.  This means that if you had 2 web apps (Foo and Bar) then
    "/index.asp" on "Foo" might get handled by "Bar::_index_asp" or vice versa.

2010-02-08    v1.009
  ! Upgrade Recommended !
  - ASP4::ModPerl sets $ENV{DOCUMENT_ROOT} = $r->document_root before doing 
    anything else.
  - The scaffold website output by 'asphelper' had some minor bugs:
      * email was sometimes referred to as email_address
      * The error message for the 'message' field was displaying the wrong error.

2010-02-07    v1.008
  - Multi-value form parameters (eg 3 checkboxes with the same name) will now
    *correctly* appear as an arrayref in $Form, instead of 3 values joined with
    a null byte.

Changes  view on Meta::CPAN


2010-01-27    v1.006
  - Sometimes changes in MasterPages are not immediately reflected in child pages.
    This release attempts to correct this bug.

2010-01-25    v1.005
  - Request Filters were not always matching properly
    because of a regexp bug in ASP4::FilterResolver.

2010-01-22    v1.004
  - $ENV{REQUEST_URI} was not getting set properly - this is now fixed.

2009-12-22    v1.003
  - $ENV{HTTP_REFERER} can be set and preserved properly.
  - conf/asp4-config.json will be reloaded if it is modified.  This means that
    the server does not have to be restarted for changes to asp4-config.json 
    to take effect.
  - Added ASP4::TransHandler

2009-12-17    v1.002
  - %ENV is no longer clobbered by ASP4::UserAgent.

2009-12-16    v1.001
  - Fixed a bug that prevented ASP4 for reliably detecting when an ASP script

MANIFEST  view on Meta::CPAN

Makefile.PL
MANIFEST			This list of files
META.yml
README.markdown
runprofiler.sh
runtests.sh
sbin/asp4
sbin/asp4-deploy
sbin/asp4-prep
sbin/asphelper
t/010-basic/000-setup.t
t/010-basic/010-compile.t
t/010-basic/020-pageparser.t
t/010-basic/030-pageloader.t
t/010-basic/040-httpcontextA.t
t/010-basic/050-useragent.t
t/010-basic/060-api.t
t/010-basic/070-memory-leak.t
t/010-basic/080-cleanup-handlers.t
t/010-basic/090-everything.t
t/020-bench/010-hello.t

README.markdown  view on Meta::CPAN


### Get a session variable

    my $foo = $Session->{foo};

### $Session->save()

Called automatically at the end of every successful request, causes any changes
to the `$Session` to be saved to the database.

### $Session->reset()

Call `$Session->reset()` to clear all the data out of the session and save 
it to the database.

## $Config

The ASP4 `$Config` object is stored in a simple JSON format on disk, and accessible
everywhere within your entire ASP4 application as the global `$Config` object.

If ever you find yourself in a place without a `$Config` object, you can get one
like this:

README.markdown  view on Meta::CPAN

    ...

Suppose you had the following tables in your database:

    create table users (
      user_id     bigint unsigned not null primary key auto_increment,
      email       varchar(200) not null,
      password    char(32) not null,
      created_on  timestamp not null default current_timestamp,
      unique(email)
    ) engine=innodb charset=utf8;
    

    create table messages (
      message_id    bigint unsigned not null primary key auto_increment,
      from_user_id  bigint unsigned not null,
      to_user_id    bigint unsigned not null,
      subject       varchar(100) not null,
      body          text,
      created_on    timestamp not null default current_timestamp,
      foreign key fk_messages_to_senders (from_user_id) references users (user_id) on delete cascade,
      foreign key fk_messages_to_recipients (to_user_id) references users (user_id) on delete cascade
    ) engine=innodb charset=utf8;

__NOTE:__ It's best to assign every ASP4 application its own namespace.  For this
example the namespace is `App::db::`

Create the file `lib/App::db/model.pm` and add the following lines:

    package App::db::model;
    

    use strict;

README.markdown  view on Meta::CPAN

    package App::db::user;
    

    use strict;
    use warnings 'all';
    use base 'App::db::model';
    use Digest::MD5 'md5_hex';
    use ASP4::ConfigLoader;
    

    __PACKAGE__->set_up_table('users');
    

    __PACKAGE__->has_many(
      messages_in =>
        'App::db::message'  =>
          'to_user_id'
    );
    

    __PACKAGE__->has_many(

README.markdown  view on Meta::CPAN


      $result ? return $result : return;
    }
    

    # Convert a password string into its hashed value:
    sub hash_password {
      my ($self, $str) = @_;
      

      my $key = ASP4::ConfigLoader->load->system->settings->signing_key;
      return md5_hex( $str . $key );
    }
    

    1;# return true:

`lib/App/db/message.pm`

    package App::db::message;
    

    use strict;
    use warnings 'all';
    use base 'App::db::model';
    

    __PACKAGE__->set_up_table('messages');
    

    __PACKAGE__->belongs_to(
      sender  =>
        'App::db::user' =>
          'from_user_id'
    );
    

    __PACKAGE__->belongs_to(

README.markdown  view on Meta::CPAN


Create your MasterPage like this:

File: `htdocs/masters/global.asp`

    <%@ MasterPage %>
    <!DOCTYPE html>
    <html>
      <head>
        <title><asp:ContentPlaceHolder id="meta_title"></asp:ContentPlaceHolder></title>
        <meta charset="utf-8" />
      </head>
      <body>
        <h1><asp:ContentPlaceHolder id="headline"></asp:ContentPlaceHolder></h1>
        <asp:ContentPlaceHolder id="main_content"></asp:ContentPlaceHolder>
      </body>
    </html>

File: `htdocs/index.asp`

    <%@ Page UseMasterPage="/masters/global.asp" %>

inc/Module/Install.pm  view on Meta::CPAN

#line 1
package Module::Install;

# For any maintainers:
# The load order for Module::Install is a bit magic.
# It goes something like this...
#
# IF ( host has Module::Install installed, creating author mode ) {
#     1. Makefile.PL calls "use inc::Module::Install"
#     2. $INC{inc/Module/Install.pm} set to installed version of inc::Module::Install
#     3. The installed version of inc::Module::Install loads
#     4. inc::Module::Install calls "require Module::Install"
#     5. The ./inc/ version of Module::Install loads
# } ELSE {
#     1. Makefile.PL calls "use inc::Module::Install"
#     2. $INC{inc/Module/Install.pm} set to ./inc/ version of Module::Install
#     3. The ./inc/ version of Module::Install loads
# }

BEGIN {
	require 5.004;
}
use strict 'vars';

use vars qw{$VERSION};
BEGIN {

inc/Module/Install.pm  view on Meta::CPAN

	*inc::Module::Install::VERSION = *VERSION;
	@inc::Module::Install::ISA     = __PACKAGE__;

}





# Whether or not inc::Module::Install is actually loaded, the
# $INC{inc/Module/Install.pm} is what will still get set as long as
# the caller loaded module this in the documented manner.
# If not set, the caller may NOT have loaded the bundled version, and thus
# they may not have a MI version that works with the Makefile.PL. This would
# result in false errors or unexpected behaviour. And we don't want that.
my $file = join( '/', 'inc', split /::/, __PACKAGE__ ) . '.pm';
unless ( $INC{$file} ) { die <<"END_DIE" }

Please invoke ${\__PACKAGE__} with:

	use inc::${\__PACKAGE__};

not:

inc/Module/Install/Metadata.pm  view on Meta::CPAN

	}

	return 1;
}

sub all_from {
	my ( $self, $file ) = @_;

	unless ( defined($file) ) {
		my $name = $self->name or die(
			"all_from called with no args without setting name() first"
		);
		$file = join('/', 'lib', split(/-/, $name)) . '.pm';
		$file =~ s{.*/}{} unless -e $file;
		unless ( -e $file ) {
			die("all_from cannot find $file from $name");
		}
	}
	unless ( -f $file ) {
		die("The path '$file' does not exist, or is not a file");
	}

inc/Module/Install/Metadata.pm  view on Meta::CPAN

	return $self->{values}{no_index};
}

sub read {
	my $self = shift;
	$self->include_deps( 'YAML::Tiny', 0 );

	require YAML::Tiny;
	my $data = YAML::Tiny::LoadFile('META.yml');

	# Call methods explicitly in case user has already set some values.
	while ( my ( $key, $value ) = each %$data ) {
		next unless $self->can($key);
		if ( ref $value eq 'HASH' ) {
			while ( my ( $module, $version ) = each %$value ) {
				$self->can($key)->($self, $module => $version );
			}
		} else {
			$self->can($key)->($self, $value);
		}
	}

lib/ASP4.pm  view on Meta::CPAN


=head3 Get a session variable

  my $foo = $Session->{foo};

=head3 $Session->save()

Called automatically at the end of every successful request, causes any changes
to the C<$Session> to be saved to the database.

=head3 $Session->reset()

Call C<< $Session->reset() >> to clear all the data out of the session and save 
it to the database.

=head2 $Config

The ASP4 C<$Config> object is stored in a simple JSON format on disk, and accessible
everywhere within your entire ASP4 application as the global C<$Config> object.

If ever you find yourself in a place without a C<$Config> object, you can get one
like this:

lib/ASP4.pm  view on Meta::CPAN

  ...

Suppose you had the following tables in your database:

  create table users (
    user_id     bigint unsigned not null primary key auto_increment,
    email       varchar(200) not null,
    password    char(32) not null,
    created_on  timestamp not null default current_timestamp,
    unique(email)
  ) engine=innodb charset=utf8;
  
  create table messages (
    message_id    bigint unsigned not null primary key auto_increment,
    from_user_id  bigint unsigned not null,
    to_user_id    bigint unsigned not null,
    subject       varchar(100) not null,
    body          text,
    created_on    timestamp not null default current_timestamp,
    foreign key fk_messages_to_senders (from_user_id) references users (user_id) on delete cascade,
    foreign key fk_messages_to_recipients (to_user_id) references users (user_id) on delete cascade
  ) engine=innodb charset=utf8;

B<NOTE:> It's best to assign every ASP4 application its own namespace.  For this
example the namespace is C<App::db::>

Create the file C<lib/App::db/model.pm> and add the following lines:

  package App::db::model;
  
  use strict;
  use warnings 'all';

lib/ASP4.pm  view on Meta::CPAN

C<lib/App/db/user.pm>

  package App::db::user;
  
  use strict;
  use warnings 'all';
  use base 'App::db::model';
  use Digest::MD5 'md5_hex';
  use ASP4::ConfigLoader;
  
  __PACKAGE__->set_up_table('users');
  
  __PACKAGE__->has_many(
    messages_in =>
      'App::db::message'  =>
        'to_user_id'
  );
  
  __PACKAGE__->has_many(
    messages_out  =>
      'App::db::message'  =>

lib/ASP4.pm  view on Meta::CPAN

      password  => $self->hash_password( $args{password} ),
    );
    
    $result ? return $result : return;
  }
  
  # Convert a password string into its hashed value:
  sub hash_password {
    my ($self, $str) = @_;
    
    my $key = ASP4::ConfigLoader->load->system->settings->signing_key;
    return md5_hex( $str . $key );
  }
  
  1;# return true:

C<lib/App/db/message.pm>

  package App::db::message;
  
  use strict;
  use warnings 'all';
  use base 'App::db::model';
  
  __PACKAGE__->set_up_table('messages');
  
  __PACKAGE__->belongs_to(
    sender  =>
      'App::db::user' =>
        'from_user_id'
  );
  
  __PACKAGE__->belongs_to(
    recipient =>
      'App::db::user' =>

lib/ASP4.pm  view on Meta::CPAN


Create your MasterPage like this:

File: C<htdocs/masters/global.asp>

  <%@ MasterPage %>
  <!DOCTYPE html>
  <html>
    <head>
      <title><asp:ContentPlaceHolder id="meta_title"></asp:ContentPlaceHolder></title>
      <meta charset="utf-8" />
    </head>
    <body>
      <h1><asp:ContentPlaceHolder id="headline"></asp:ContentPlaceHolder></h1>
      <asp:ContentPlaceHolder id="main_content"></asp:ContentPlaceHolder>
    </body>
  </html>

File: C<htdocs/index.asp>

  <%@ Page UseMasterPage="/masters/global.asp" %>

lib/ASP4/API.pm  view on Meta::CPAN

    print $res->content;
  }
  
  # Access your test data:
  warn $res->test_data->contact_form->email;
  
  # Access your properties YAML:
  warn $res->properties->contact_form->email->is_missing;
  
  # Access the application config:
  warn $api->config->system->settings->foo;

=head1 DESCRIPTION

C<ASP4::API> is B<very useful for unit tests> - specifically when writing tests
for the actual web pages themselves.

=head2 Example Unit Test

  #!/usr/bin/perl -w
  

lib/ASP4/Config.pm  view on Meta::CPAN

    join '/', @parts;
  })->();
  $s->{web}->{project_root} = $project_root;
  no warnings 'uninitialized';
  foreach( @{ $s->{system}->{libs} } )
  {
    $_ =~ s/\@ServerRoot\@/$root/;
    $_ =~ s/\@ProjectRoot\@/$project_root/;
  }# end foreach()
  
  my $settings = $s->{system}->{settings};
  foreach( keys %$settings )
  {
    $settings->{$_} =~ s/\@ServerRoot\@/$root/;
    $settings->{$_} =~ s/\@ProjectRoot\@/$project_root/;
  }# end foreach()
  
  foreach my $key (qw/ application handler www page_cache /)
  {
    $s->{web}->{"$key\_root"} =~ s/\@ServerRoot\@/$root/;
    $s->{web}->{"$key\_root"} =~ s/\@ProjectRoot\@/$project_root/;
    $s->{web}->{"$key\_root"} =~ s{\\\\}{\\}g;
  }# end foreach()
  $s->{web}->{project_root} = $project_root;
  

lib/ASP4/Config.pm  view on Meta::CPAN


=pod

=head1 NAME

ASP4::Config - Central configuration for ASP4

=head1 SYNOPSIS

  # Settings:
  $Config->system->settings->some_setting;
  $Config->system->settings->another_setting;
  
  # Error-handling:
  $Config->errors->error_handler;
  $Config->errors->mail_errors_to;
  $Config->errors->mail_errors_from;
  $Config->errors->smtp_server;
  
  # Web:
  $Config->web->application_name;
  $Config->web->application_root;

lib/ASP4/Config.pm  view on Meta::CPAN

        "@ProjectRoot@/lib"
      ],
      "load_modules": [
        "DBI",
        "DBD::SQLite"
      ],
      "env_vars": {
        "myvar":        "Some-Value",
        "another_var":  "Another Value"
      },
      "settings": {
        "foo": "bar",
        "baz": "bux"
      }
    },
    "errors": {
      "error_handler":    "ASP4::ErrorHandler",
      "mail_errors_to":   "you@yours.com",
      "mail_errors_from": "root@localhost",
      "smtp_server":      "localhost"
    },

lib/ASP4/ConfigNode/System.pm  view on Meta::CPAN



sub post_processors
{
  my $s = shift;
  
  @{ $s->{post_processors} || [ ] };
}# end post_processors()


sub settings
{
  my $s = shift;
  
  return $s->{settings} || { };
}# end settings()

1;# return true:

=pod

=head1 NAME

ASP4::ConfigNode::System - the 'system' portion of the config.

=head1 SYNOPSIS

lib/ASP4/ConfigNode/System.pm  view on Meta::CPAN


A list of Perl modules that should be loaded automatically.

=head2 post_processors

A list of L<ASP4::ConfigPostProcessor> modules that should be given the ability to alter the config before
it is considered "ready for use" by the rest of the application.

=head2 env_vars

A hash of C<%ENV> variables that should be set.

=head2 settings

A collection of special read-only values that should be available throughout the application.

Examples include encryption keys, API keys and username/password combos to access remote services.

=head1 BUGS

It's possible that some bugs have found their way into this release.

Use RT L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=ASP4> to submit bug reports.

lib/ASP4/ErrorHandler.pm  view on Meta::CPAN



sub error_html
{
  my ($s, $error) = @_;
  
  my $msg = <<"ERROR";
<!DOCTYPE html>
<html>
<head><title>500 Server Error</title>
<meta charset="utf-8" />
<style type="text/css">
HTML,BODY {
  background-color: #FFFFFF;
}
HTML,BODY,P,DIV {
  font-family: Arial, Helvetica, Sans-Serif;
}
HTML,BODY,P,PRE,DIV {
  font-size: 12px;
}

lib/ASP4/HTTPContext.pm  view on Meta::CPAN

  my $web = $s->config->web;
  $s->config->load_class( $web->handler_resolver );
  $s->config->load_class( $web->handler_runner );
  $s->config->load_class( $s->config->data_connections->session->manager );
  $s->config->load_class( $web->filter_resolver );
  
  return $s->is_subrequest ? $s : $_instance = $s;
}# end new()


sub setup_request
{
  my ($s, $r, $cgi) = @_;
  
  $ENV{DOCUMENT_ROOT} = $r->document_root;
  $s->{r} = $r;
  $s->{cgi} = $cgi;
  
  # Must instantiate $_instance before creating the other objects:
  $s->{request}   ||= ASP4::Request->new();
  $s->{response}  ||= ASP4::Response->new();

lib/ASP4/HTTPContext.pm  view on Meta::CPAN

  if( $s->do_disable_session_state )
  {
    $s->{session} ||= ASP4::SessionStateManager::NonPersisted->new( $s->r );
  }
  else
  {
    $s->{session} ||= $s->config->data_connections->session->manager->new( $s->r );
  }# end if()
  
  return $_instance;
}# end setup_request()


# Intrinsics:
sub current   { $_instance || shift->new }
sub request   { shift->{request} }
sub response  { shift->{response} }
sub server    { shift->{server} }
sub session   { shift->{session} }
sub config    { shift->{config} }
sub stash     { shift->{stash} }

lib/ASP4/ModPerl.pm  view on Meta::CPAN

      $r->status( 500 );
      return $r->status;
    }# end if()
    
    return 404 unless $handler_class;
    
    eval {
      my $cgi = CGI->new( $r );
      my %args = map { my ($k,$v) = split /\=/, $_; ( $k => $v ) } split /&/, $ENV{QUERY_STRING};
      map { $cgi->param($_ => $args{$_}) } keys %args;
      $context->setup_request( $r, $cgi);
      $context->execute;
    };
    if( $@ )
    {
      if( $@ =~ m/Software\scaused\sconnection\sabort/ )
      {
        return 0;
      }# end if()
      warn $@;
      $r->status( 500 );
    }# end if()
    return $r->status =~ m/^2/ ? 0 : $r->status == 500 ? 0 : $r->status;
  }
  else
  {
    my $cgi = CGI->new( $r );
    eval {
      $context->setup_request( $r, $cgi );
      $context->execute;
    };
    if( $@ =~ m/Software\scaused\sconnection\sabort/ )
    {
      return 0;
    }# end if()
    warn $@ if $@;
    
    
    if( $context->response->Status == 200 )

lib/ASP4/Response.pm  view on Meta::CPAN

  my $cgi = $s->context->cgi;
  (my $uri = $file) =~ s/^\Q$root\E//;
  my $r = ASP4::Mock::RequestRec->new(
    uri   => $uri,
    args  => $original_r->args,
  );
  SCOPE: {
    local $ASP4::HTTPContext::_instance = $context;
    local $ENV{SCRIPT_NAME} = $uri;
    local $ENV{SCRIPT_FILENAME} = $file;
    $context->setup_request( $r, $cgi );
    $context->execute( $args, 1 );
  };
  
  return $context->r->buffer;
}# end _subrequest()


#sub _subrequest
#{
#  my ($s, $file, $args) = @_;

lib/ASP4/Response.pm  view on Meta::CPAN

#  my $original_r = $s->context->r;
#  my $root = $s->context->config->web->www_root;
#  (my $uri = $file) =~ s/^\Q$root\E//;
#  my $r = ASP4::Mock::RequestRec->new(
#    uri   => $uri,
#    args  => $original_r->args,
#  );
#  local $ENV{SCRIPT_NAME} = $uri;
#  local $ENV{SCRIPT_FILENAME} = $file;
#  my $original_status = $s->Status();
#  $s->context->setup_request( $r, $s->context->cgi );
#  $s->context->execute( $args, 1 );
#  $s->Flush;
#  $s->Status( $original_status );
#  my $buffer = $s->context->purge_buffer();
#  $s->context->{r} = $original_r;
#  $s->context->did_end( 0 );
#  return $r->buffer;
#}# end _subrequest()


lib/ASP4/Response.pm  view on Meta::CPAN

  expires => '30D'  # A month

=back

=item * path

Defaults to "C</>" - you can restrict the "path" that the cookie will apply to.

=item * domain

Defaults to whatever you set your config->data_connections->session->cookie_domain to
in your asp4-config.json.  Otherwise defaults to C<$ENV{HTTP_HOST}>.

You can override the defaults by passing in a domain, but the browser may not accept
other domains.  See L<http://www.ietf.org/rfc/rfc2109.txt> for details.

=back

=head2 Redirect( $url )

Causes the following HTTP header to be sent:

lib/ASP4/SessionStateManager.pm  view on Meta::CPAN

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();
  unless( $id && $s->verify_session_id( $id, $conn->session_timeout ) )
  {
    $s->{SessionID} = $s->new_session_id();
    $s->write_session_cookie($r);

lib/ASP4/SessionStateManager.pm  view on Meta::CPAN


sub is_changed
{
  my $s = shift;
  
  no warnings 'uninitialized';
  $s->_hash ne $s->{__signature};
}# end is_changed()


sub reset
{
  my $s = shift;
  
  delete($s->{$_}) for grep { $_ ne 'SessionID' } keys %$s;
  $s->save;
  return;
}# end reset()


sub DESTROY
{
  my $s = shift;
  
  return undef(%$s) unless $s->{SessionID};
  
  unless( $s->is_read_only )
  {

lib/ASP4/SessionStateManager.pm  view on Meta::CPAN


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
being saved at the end of the request.

B<NOTE:> A side-effect is that calling C<< $Session->save() >> after calling C<< $Session->is_read_only(1) >>
will B<*NOT*> prevent changes from being saved B<ON PURPOSE>.  Explicitly calling C<< $Session->save() >>
will still cause the session data to be stored.  Setting C<< $Session->is_read_only(1) >> will only
prevent the default behavior of saving session state at the end of each successful request.

=head1 PUBLIC METHODS

=head2 save( )

Causes the session data to be saved. (Unless C<< $Session->is_read_only(1) >> is set.)

=head2 reset( )

Causes the session data to be emptied.

=head1 BUGS

It's possible that some bugs have found their way into this release.

Use RT L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=ASP4> to submit bug reports.

=head1 HOMEPAGE

lib/ASP4/SessionStateManager/InMemory.pm  view on Meta::CPAN



sub save
{
  my ($s) = @_;
  
  1;
}# end save()


sub reset
{
  my $s = shift;
  
  map { delete($s->{$_}) } grep { $_ ne 'SessionID' } keys %$s;
  $s->save;
  return;
}# end reset()

1;# return true:

lib/ASP4/SessionStateManager/Memcached.pm  view on Meta::CPAN

  
  return unless $s->{SessionID};
  no warnings 'uninitialized';
  my $seconds_since_last_modified = time() - ($s->{__lastMod} || 0);
  return unless $s->is_changed || ( $seconds_since_last_modified > 60 );
  $s->{__lastMod} = time();
  $s->sign;
  
  my %clone = %$s;
  my $json = encode_json(\%clone);
  $memd->set( $s->{SessionID}, $json, $s->{__ttl} );
}# end save()


sub reset
{
  my $s = shift;
  
  map { delete($s->{$_}) } grep { $_ !~ m{^(SessionID|__ttl)$} } keys %$s;
  $s->save;
  return;
}# end reset()

1;# return true:




lib/ASP4/UserAgent.pm  view on Meta::CPAN

  %ENV = (
    %{ $s->{env} },
    HTTP_HOST       => $s->{env}->{HTTP_HOST} || $s->{cwd},
    HTTP_REFERER    => $referer || '',
    DOCUMENT_ROOT   => $s->config->web->www_root,
    REQUEST_METHOD  => 'GET',
    CONTENT_TYPE    => 'application/x-www-form-urlencoded',
    HTTP_COOKIE     => $s->http_cookie,
    REQUEST_URI     => $uri,
  );
  my $cgi = $s->_setup_cgi( $req );
  my ($uri_no_args, $querystring) = split /\?/, $uri;
  my $r = ASP4::Mock::RequestRec->new( uri => $uri_no_args, args => $querystring );
  
  my $current_is_subrequest = $ASP4::HTTPContext::_instance ? $ASP4::HTTPContext::_instance->{is_subrequest} ? 1 : 0 : 0;
  $s->{context} = ASP4::HTTPContext->new( is_subrequest => $current_is_subrequest ? 1 : 0 );
  
  return do {
    local $ASP4::HTTPContext::_instance = $s->context;
    $s->context->setup_request( $r, $cgi );
    $s->_setup_response( $s->context->execute() );
  };
}# end get()


sub post
{
  my ($s, $uri, $args) = @_;
  
  chdir( $s->{cwd} );
  

lib/ASP4/UserAgent.pm  view on Meta::CPAN

  my $referer = $ENV{HTTP_REFERER};
  %ENV = (
    %{ $s->{env} },
    HTTP_REFERER    => $referer || '',
    DOCUMENT_ROOT   => $s->config->web->www_root,
    REQUEST_METHOD  => 'POST',
    CONTENT_TYPE    => 'application/x-www-form-urlencoded',
    HTTP_COOKIE     => $s->http_cookie,
    REQUEST_URI     => $uri,
  );
  my $cgi = $s->_setup_cgi( $req );
  my ($uri_no_args, $querystring) = split /\?/, $uri;
  my $r = ASP4::Mock::RequestRec->new( uri => $uri_no_args, args => $querystring );
  $s->{context} = ASP4::HTTPContext->new( is_subrequest => $ASP4::HTTPContext::_instance ? 1 : 0 );
  return do {
    local $ASP4::HTTPContext::_instance = $s->context;
    $s->context->setup_request( $r, $cgi );
    $s->_setup_response( $s->context->execute() );
  };
}# end post()


sub upload
{
  my ($s, $uri, $args) = @_;
  
  chdir( $s->{cwd} );
  

lib/ASP4/UserAgent.pm  view on Meta::CPAN

  my $referer = $ENV{HTTP_REFERER};
  %ENV = (
    %{ $s->{env} },
    HTTP_REFERER    => $referer || '',
    DOCUMENT_ROOT   => $s->config->web->www_root,
    REQUEST_METHOD  => 'POST',
    CONTENT_TYPE    => 'multipart/form-data',
    HTTP_COOKIE     => $s->http_cookie,
    REQUEST_URI     => $uri,
  );
  my $cgi = $s->_setup_cgi( $req );
  my ($uri_no_args, $querystring) = split /\?/, $uri;
  my $r = ASP4::Mock::RequestRec->new( uri => $uri_no_args, args => $querystring );
  $s->{context} = ASP4::HTTPContext->new( is_subrequest => $ASP4::HTTPContext::_instance ? 1 : 0 );
  return do {
    local $ASP4::HTTPContext::_instance = $s->context;
    $s->context->setup_request( $r, $cgi );
    $s->_setup_response( $s->context->execute() );
  };
}# end upload()


sub submit_form
{
  my ($s, $form) = @_;
  
  chdir( $s->{cwd} );
  

lib/ASP4/UserAgent.pm  view on Meta::CPAN

  my $referer = $ENV{HTTP_REFERER};
  %ENV = (
    %{ $s->{env} },
    HTTP_REFERER    => $referer || '',
    DOCUMENT_ROOT   => $s->config->web->www_root,
    REQUEST_METHOD  => uc( $req->method ),
    CONTENT_TYPE    => $form->enctype ? $form->enctype : 'application/x-www-form-urlencoded',
    HTTP_COOKIE     => $s->http_cookie,
    REQUEST_URI     => $form->action,
  );
  my $cgi = $s->_setup_cgi( $req );
  my ($uri_no_args, $querystring) = split /\?/, $req->uri;
  my $r = ASP4::Mock::RequestRec->new( uri => $uri_no_args, args => $querystring );
  my $current_is_subrequest = $ASP4::HTTPContext::_instance ? $ASP4::HTTPContext::_instance->{is_subrequest} ? 1 : 0 : 0;
  $s->{context} = ASP4::HTTPContext->new( is_subrequest => $current_is_subrequest ? 1 : 0 );
  return do {
    local $ASP4::HTTPContext::_instance = $s->context;
    $s->context->setup_request( $r, $cgi );
    $s->_setup_response( $s->context->execute() );
  };
}# end submit_form()


sub add_cookie
{
  my ($s, $name, $value) = @_;
  
  $s->{cookies}->{$name} = $value;
}# end add_cookie()

lib/ASP4/UserAgent.pm  view on Meta::CPAN

sub http_cookie
{
  my $s = shift;
  
  join '; ',
    map { ASP4::SimpleCGI->escape($_) . '=' . ASP4::SimpleCGI->escape($s->{cookies}->{$_}) }
    keys %{$s->{cookies}};
}# end http_cookie()


sub _setup_response
{
  my ($s, $response_code) = @_;
  
  $response_code = 200 if ($response_code || 0) eq '0';
  my $response = HTTP::Response->new( $response_code );
  
  # XXX: Sometimes this dies with 'HTTP::Message requires bytes' or similar:
  eval { $response->content( $s->context->r->buffer ) };
  if( $@ )
  {

lib/ASP4/UserAgent.pm  view on Meta::CPAN

    $response->content( $ascii );
  }# end if()
  
  $response->header( 'Content-Type' => $s->context->response->{ContentType} );
  
  foreach my $header ( $s->context->response->Headers, $s->context->r->err_headers_out )
  {
    if( my ($k,$v) = each(%$header) )
    {
      $response->header( lc($k) => $v );
      if( lc($k) eq 'set-cookie' )
      {
        my @cookies = ( );
        if( ref($v) )
        {
          @cookies = @$v;
        }
        else
        {
          @cookies = ( $v );
        }# end if()

lib/ASP4/UserAgent.pm  view on Meta::CPAN

        }# end foreach()
      }# end if()
    }# end while()
  }# end foreach()
  
  $s->context->r->pool->call_cleanup_handlers();
  
#  $s->context->DESTROY;
  
  return $response;
}# end _setup_response()


sub _setup_cgi
{
  my ($s, $req) = @_;

  if( $s->{referer} )
  {
    ($s->{referer}) = $req->uri =~ m/.*?(\/[^\?]+)/;
    $req->referer( $s->{referer} );
  }
  else
  {

lib/ASP4/UserAgent.pm  view on Meta::CPAN

      body            => $req->content,
      content_type    => $req->headers->{'content-type'},
      content_length  => $req->headers->{'content-length'},
    );
  }
  else
  {
    # Simple 'GET' request:
    return ASP4::SimpleCGI->new( querystring => $ENV{QUERY_STRING} );
  }# end if()
}# end _setup_cgi()


sub DESTROY
{
  my $s = shift;
  undef(%$s);
}# end DESTROY()

1;# return true:

sbin/asphelper  view on Meta::CPAN



# Write the ddl.sql file:
unless( -f "common/sbin/ddl.sql" )
{
  warn "common/sbin/ddl.sql\n";
  open my $ofh, '>', "common/sbin/ddl.sql"
    or die "Cannot open 'common/sbin/ddl.sql' for writing: $!";
  print $ofh <<"SQL";

set foreign_key_checks = 0;
drop table if exists asp_sessions;
set foreign_key_checks = 1;

create table asp_sessions (
  session_id   char(32) not null primary key,
  session_data blob,
  created_on   datetime default null,
  modified_on  datetime default null
) engine=innodb charset=utf8;

SQL
  close($ofh);
  open my $ifh, "common/sbin/ddl.sql"
    or die "Cannot open 'common/sbin/ddl.sql' for reading: $!";
  local $/ = ';';
  while( my $cmd = <$ifh> )
  {
    $cmd =~ s/^\s+//s;
    $cmd =~ s/\s+$//s;

sbin/asphelper  view on Meta::CPAN

\=head1 SYNOPSIS

  # In your class:
  
  package $appName\::db::thing;
  
  use strict;
  use warnings 'all';
  use base '$appName\::db::model';
  
  __PACKAGE__->set_up_table('things');
  
  1;# return true:

\=head1 DESCRIPTION

This module was generated by $0 on @{[ scalar(localtime()) ]}.

B<***IT IS SAFE to make changes to this file, as it will not be overwritten.***>.

\=head1 SEE ALSO

sbin/asphelper  view on Meta::CPAN

    "post_processors": [
    ],
    "libs": [
      "@ServerRoot@/lib",
      "@ProjectRoot@/common/lib"
    ],
    "load_modules": [
    ],
    "env_vars": {
    },
    "settings": {
    }
  },
  "errors": {
    "error_handler":    "ASP4::ErrorHandler",
    "mail_errors_to":   "%email%",
    "mail_errors_from": "root@localhost",
    "smtp_server":      "localhost"
  },
  "web": {
    "application_name": "%appName%",

t/010-basic/010-compile.t  view on Meta::CPAN

use_ok( 'ASP4::MasterPage' );
use_ok( 'ASP4::PageParser' );

ok( my $config = ASP4::ConfigLoader->load(), 'load' );

is(
  $config->web->application_name => "DefaultApp"
);

is(
  $config->system->settings->foo => "bar", "foo = bar"
);

is(
  $config->system->env_vars->myvar => "Some-Value"
);

t/010-basic/040-httpcontextA.t  view on Meta::CPAN

After TrapInclude:
), "Response.TrapInclude works properly";
};

sub do_request
{
  my $url = shift;
  my $req = ASP4::Mock::RequestRec->new( uri => $url );
  my $cgi = ASP4::SimpleCGI->new();
  my $context = ASP4::HTTPContext->new();
  $context->setup_request( $req, $cgi );
  $context->execute( );
  return $context;
}# end do_request()



t/conf/asp4-config.json  view on Meta::CPAN

    ],
    "load_modules": [
      "DBI",
      "DBD::SQLite"
    ],
    
    "env_vars": {
      "myvar":        "Some-Value",
      "another_var":  "Another Value"
    },
    "settings": {
      "foo": "bar",
      "baz": "bux"
    }
  },
  "errors": {
    "error_handler":    "ASP4::ErrorHandler",
    "mail_errors_to":   "jdrago_999@yahoo.com",
    "mail_errors_from": "root@localhost",
    "smtp_server":      "localhost"
  },

t/handlers/dev/encoding/hello.pm  view on Meta::CPAN

      original  => '你好,世界!',
      encoded   => 'JiMyMDMyMDsmIzIyOTA5OyYjNjUyOTI7JiMxOTk5MDsmIzMwMDI4OyYjNjUyODE7',
    },
    foo => {
      original  => 'Bjòrknù',
    }
  };
  
  my $lang = $Form->{lang}
    or return;
  $Response->ContentType("text/plain; charset=utf-8");
  $Response->Write(
    encode_utf8(
      $hellos->{$lang}->{original}
    )
  );
}# end run()

1;# return true:

t/htdocs/index.asp  view on Meta::CPAN

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>ASP4 Installed</title>
  <style type="text/css">
  HTML, BODY {
    margin: 0px;
    padding: 0px;
    border: 0px;
    font-size: 14px;
    font-family: Verdana, Arial, Sans-Serif;
    background-color: #333333;
    color: #000000;



( run in 0.945 second using v1.01-cache-2.11-cpan-49f99fa48dc )