ASP4

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

  - eric.hayes++

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

2012-01-23    1.073
  - Added $Request->Header($name)
    (Somehow we've gotten along all this time without it.)

2012-01-23    1.072
  - More tweaks on ASP4::SessionStateManager's default internal behavior
    has resulted in some more-than-modest performance gains.
  - Disabling session-state can result in 630 requests/second on a simple 
    master/child "content" page, and 475 requests/second on a page that
    includes reading data from a database (using Class::DBI::Lite of course).
    * Results from `ab` on a Dell E6510 (quad-dual-core-i7, 8GB RAM, Ubuntu 10.10)

2012-01-22    1.071
  - ASP4::HTTPContext now triggers the SessionStateManager's save() method
    when the context is DESTROY'd.

Changes  view on Meta::CPAN

[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
    before deciding whether is should persist its changes in ->save().

[New Features]
  - $Session->is_read_only(1) is new.  Setting it to a true value (eg: 1) will prevent
    the default behavior of calling $Session->save() at the end of each successful request.

2011-04-08    v1.043
  - Documentation overhaul.

2011-03-23    v1.042
  - Fixed sporadic error in master pages that looks like this:
    Can't call method "Write" on an undefined value at /tmp/PAGE_CACHE/BStat/_masters_global_asp.pm line 1.
  - Apparently $s->init_asp_objects($context) was not getting called before the 
    master page's run() method was called, resulting in a call to $Response->Write(...)
    before $Response had been initialized.

MANIFEST  view on Meta::CPAN

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
t/030-filters/010-seo.t
t/040-round2/010-include-missing.t
t/040-round2/020-api-in-handler.t
t/040-round2/030-redirect-after-trapinclude.t
t/050-encoding/010-default.t
t/999-finish/000-cleanup.t
t/conf/asp4-config.json
t/conf/httpd.conf
t/etc/properties.yaml
t/etc/test_fixtures.json
t/etc/test_fixtures.yaml
t/handlers/dev/api_inside_handler.pm
t/handlers/dev/encoding/hello.pm
t/handlers/dev/headers.pm
t/handlers/dev/redirect_after_trapinclude.pm

README.markdown  view on Meta::CPAN

    # The rest of these arguments are optional:
    

    # Expires: (If you don't specify the "expires" argument, the cookie will
    # be deleted when the browser is closed.
    expires => "3D",  # 3 days
    expires => "3H",  # or 3 hours
    expires => "3M",  # or 3 minutes
    

    # Domain: (defaults to $ENV{HTTP_HOST})
    domain  => ".example.com",    # works for *.example.com
    domain  => "www.example.com", # will ONLY work for www.example.com
    

      # Path:
      path    => "/some/folder/"    # will ONLY work within /some/folder/ on your website
    );

### $Response->Include( $path, %args )

README.markdown  view on Meta::CPAN

        "password":         "db-pAsswOrd"
      }
    ...

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;

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


sub prompt {
	shift;

	# Infinite loop protection
	my @c = caller();
	if ( ++$seen{"$c[1]|$c[2]|$_[0]"} > 3 ) {
		die "Caught an potential prompt infinite loop ($c[1]|$c[2]|$_[0])";
	}

	# In automated testing, always use defaults
	if ( $ENV{AUTOMATED_TESTING} and ! $ENV{PERL_MM_USE_DEFAULT} ) {
		local $ENV{PERL_MM_USE_DEFAULT} = 1;
		goto &ExtUtils::MakeMaker::prompt;
	} else {
		goto &ExtUtils::MakeMaker::prompt;
	}
}

sub makemaker_args {
	my $self = shift;

lib/ASP4.pm  view on Meta::CPAN

    value => "the-value",
    
    # The rest of these arguments are optional:
    
    # Expires: (If you don't specify the "expires" argument, the cookie will
    # be deleted when the browser is closed.
    expires => "3D",  # 3 days
    expires => "3H",  # or 3 hours
    expires => "3M",  # or 3 minutes
    
    # Domain: (defaults to $ENV{HTTP_HOST})
    domain  => ".example.com",    # works for *.example.com
    domain  => "www.example.com", # will ONLY work for www.example.com
    
    # Path:
    path    => "/some/folder/"    # will ONLY work within /some/folder/ on your website
  );

=head3 $Response->Include( $path, %args )

ASP4's C<$Response> object offers 3 different include methods.

lib/ASP4.pm  view on Meta::CPAN

      "password":         "db-pAsswOrd"
    }
  ...

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;

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

B<*IF*> you have defined a "routes" section in your config - like this:

  ...
  "web": {
    ...
    "routes": [
      {
        "name":   "Wiki",
        "path":   "/:lang-:locale/{*page}",
        "target": "/wiki-page.asp",
        "defaults": {
          "page":   "home",
          "lang":   "en",
          "locale": "us"
        }
      }
    ]
    ...
  }

Then the C<router> property will return a L<Router::Generic> object based on your routes.

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

  
  # Pass in your own info:
  unless( $something ) {
    my $error = ASP4::Error->new(
      message => "If can, can.  If no can, no can!"
    );
  }
  
=head1 DESCRIPTION

ASP4 provides a simple means of dealing with errors.  It emails them, by default,
to an email address you specify.

Sometimes that is not convenient.  Maybe you want to do something special with
the error - like log it someplace special.

ASP4::Error is a simple representation of a server-side error.

=head1 PUBLIC READ-ONLY PROPERTIES

=head2 domain

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

=head2 code

A string.  Includes the 5 lines of code before and after the line of code where the error occurred.

=head2 message

Defaults to the first part of C<$@> unless otherwise specified.

=head2 stacktrace

A string - defaults to the value of C<$@>.

=head2 form_data

JSON-encoded C<$Form> object.

=head2 session_data

JSON-encoded C<$Session> object.

=head2 http_referer

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

    "errors": {
      "error_handler":    "ASP4::ErrorHandler",
      "mail_errors_to":   "you@server.com",
      "mail_errors_from": "root@localhost",
      "smtp_server":      "localhost"
    },
  ...

=head1 DESCRIPTION

This class provides a default error handler which does the following:

1) Makes a simple HTML page and prints it to the browser, telling the user
that an error has just occurred.

2) Sends that same HTML to the email address specified in the config, using the
SMTP server also specified in the config.  The email subject will look something like:

  ASP4: Error in your-site.com/index.asp

=head1 SUBCLASSING

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


  ...
    "errors": {
      "error_handler":    "ASP4::ErrorHandler::Remote",
      "post_errors_to":   "http://errors.ohno.com/post/errors/here/"
    },
  ...

=head1 DESCRIPTION

This class provides a default error handler which does the following:

1) Makes a simple HTML page and prints it to the browser, telling the user
that an error has just occurred.

2) Sends an error notification to the web address specified in the config.

The data contained within the POST will match the public properties of L<ASP4::Error>, like this:

  $VAR1 = {
            'remote_addr' => '127.0.0.1',

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


=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:

  Status: 301 Moved
  Location: $url

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


=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.

sbin/asphelper  view on Meta::CPAN

    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;

t/010-basic/000-setup.t  view on Meta::CPAN

  RaiseError => 1,
});

$dbh->do(<<"SQL");
drop table if exists asp_sessions
SQL

my $ok = $dbh->do(<<"SQL");
create table asp_sessions (
  session_id    char(32) not null primary key,
  modified_on   timestamp not null default( datetime('now','localtime') ),
  created_on    datetime not null default( datetime('now','localtime') ),
  session_data  blob
)
SQL

ok($ok, "created table");

my $id = md5_hex( rand() );
$dbh->do(<<"SQL");
insert into asp_sessions (session_id, session_data) values ('$id','test')
SQL



( run in 0.591 second using v1.01-cache-2.11-cpan-0a6323c29d9 )