Incorrect search filter: invalid characters - *.p[ml]
ASP4

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

      use ASP4::API;
      my $api; BEGIN { $api = ASP4::API->new }
      # Now load classes:
      use MyApp::Foo;
    - You can do this instead:
      use ASP4::API;
      use MyApp::Foo;
      my $api = ASP4::API->new;
    - Also no need for BEGIN { ASP4::API->init }
  - Added requirement Data::Properties::JSON.
    - JSON is a better format for test fixtures.
    - YAML can still be used.

2011-10-31    1.058
  - Added experimental deployment tools `asp4-prep` and `asp4-deploy`.
    * asp4-prep does an `svn export` and then gzips the folder and prints the *.tar.gz filename.
    * asp4-deploy decompresses the *.tar.gz, creates a symbolic link 'deploying'
      to the new folder, copies the existing config files from latest/*/conf/* 
      (if it exists) or copies conf/*.template config files and renames them without
      the *.template suffix.  If a 'latest/*' folder was found, asp4-deploy will
      run any unit tests found.  If all tests pass, then 'deploying' is removed
      and 'latest' is changed to point to the new folder.
  - TODO: Add POD for asp4-prep and asp4-deploy.  This is delayed until it's proven
    that this is the correct way for onesie-twosie deployments.

2011-10-04    1.057
  - Renamed @AppRoot@ macro to @ProjectRoot@ to avoid confusion with $Config->web->application_root
  - Adjusted package declarations in some "stealth-mode" pm files because they have no POD yet.

2011-10-03    1.056
  - Updated asphelper to include directives that disable mod_deflate and Apache2::Reload
    for ASP4 websites. RayBaksh++
  - This fixes the dreaded "This website uses an invalid form of compression" error
    that you may have gotten after trying to $Response->Status(404) within an asp script.
  - Added in-memory mock sessionstate handler for faster testing and easier installation.

2011-09-22    1.055
  - Giving credit where credit is due :-)
  - Erikdj++
  - Added *experimental* memcached session storage backend.

2011-09-20    1.054
  - Added @AppRoot@ macro for asp4-config.json.  It is 1 folder "up" from @ServerRoot@.
  - If your @ServerRoot@ is:
      /home/bart/Projects/facebook/www

Changes  view on Meta::CPAN


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.

2010-02-18    v1.012
  - MANIFEST was missing a few files that caused tests to fail.

2010-02-17    v1.011
  ! Upgrade Recommended !
  - $Response->SetCookie and $Response->ContentType were not functioning properly.
  - Added new method $Response->SetHeader.

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

MANIFEST  view on Meta::CPAN

lib/ASP4/SimpleCGI.pm
lib/ASP4/StaticHandler.pm
lib/ASP4/Test/Fixtures.pm
lib/ASP4/TransHandler.pm
lib/ASP4/UserAgent.pm
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

MANIFEST  view on Meta::CPAN

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
t/handlers/dev/seo_handler.pm
t/handlers/dev/simple.pm
t/handlers/dev/speed.pm
t/htdocs/404.asp
t/htdocs/child-returns-404.asp
t/htdocs/everything/master.asp

META.yml  view on Meta::CPAN

--- #YAML:1.0
name:               ASP4
version:            1.087
abstract:           Fast, Simple, Scalable Web Development
author:
    - John Drago <jdrago_999@yahoo.com>
license:            artistic
distribution_type:  module
test_requires:
    Test::More:           0
    Test::Memory::Cycle:  0
    Time::HiRes:          0
    HTML::Form:           0
requires:
    common::sense:            0
    Data::Properties::YAML:   0
    Cwd:                      0
    Digest::MD5:              0
    DBI:                      0

Makefile.PL  view on Meta::CPAN

use strict;
use warnings;
use inc::Module::Install;
use 5.008005;

name 'ASP4';
perl_version '5.008005';
license 'perl';
all_from 'lib/ASP4.pm';

test_requires 'Test::More'          => 0;
test_requires 'Test::Memory::Cycle' => 0;
#test_requires 'DBD::SQLite'         => 0;
test_requires 'Time::HiRes'         => 0;
test_requires 'HTML::Form'          => 0;

requires    'common::sense'           => 0;
requires    'Data::Properties::YAML'  => 0;
requires    'Data::Properties::JSON'  => 0;
requires    'Cwd'                     => 0;
requires    'Digest::MD5'             => 0;       # Session state.
requires    'DBI'                     => 0;       # Session state.
requires    'Ima::DBI::Contextual'    => 0;       # Session state.
requires    'Storable'                => 0;       # Session state.
requires    'HTTP::Date'              => 0;       # For Session timeouts.

Makefile.PL  view on Meta::CPAN

recommends  'ASP4x::Router'           => 0.020;   # For routing.

install_script 'sbin/asp4';
install_script 'sbin/asp4-prep';
install_script 'sbin/asp4-deploy';
install_script 'sbin/asphelper';
resources(
  'repository'  => 'https://github.com/jdrago999/ASP4'
);

tests_recursive();
WriteAll();

README.markdown  view on Meta::CPAN


Sends an email via [Mail::Sendmail](http://search.cpan.org/perldoc?Mail::Sendmail).  In fact it simply calls the `sendmail(...)` function
provided by [Mail::Sendmail](http://search.cpan.org/perldoc?Mail::Sendmail).

Simple Example:

    $Server->Mail(
      from    => 'foo@bar.com',
      to      => 'bar@foo.com',
      subject => 'Hello, world!',
      message => 'this is a test message'
    );

To send an HTML email do the following:

    use MIME::Base64;
    $Server->Mail(
      from                        => 'foo@bar.com',
      to                          => 'bar@foo.com',
      subject                     => 'Hello, world!',
      'content-type'              => 'text/html',

README.markdown  view on Meta::CPAN

such as in a RequestFilter - will still be there at the very end of the request -
as in a RegisterCleanup handler.

Use the `$Stash` as a great place to store a piece of data for the duration of
a single request.

# DATABASE

While ASP4 __does not require__ its users to choose any specific database (eg: MySQL or PostgreSQL)
or ORM (object-relational mapper) the __recommended__ ORM is [Class::DBI::Lite](http://search.cpan.org/perldoc?Class::DBI::Lite)
since it has been completely and thoroughly tested to be 100% compatible with ASP4.

For full documentation about [Class::DBI::Lite](http://search.cpan.org/perldoc?Class::DBI::Lite) please view its documentation.

__NOTE:__ [Class::DBI::Lite](http://search.cpan.org/perldoc?Class::DBI::Lite) must be installed in addition to ASP4 as it is a separate library.

# ASP4 QuickStart

Here is an example project to get things going.

In the `data_connections.main` section of `conf/asp4-config.json` you should have

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;

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

	my $self = shift;
	my $libs = ref $_[0] ? shift : [ shift ];
	$self->makemaker_args( LIBS => $libs );
}

sub inc {
	my $self = shift;
	$self->makemaker_args( INC => shift );
}

my %test_dir = ();

sub _wanted_t {
	/\.t$/ and -f $_ and $test_dir{$File::Find::dir} = 1;
}

sub tests_recursive {
	my $self = shift;
	if ( $self->tests ) {
		die "tests_recursive will not work if tests are already defined";
	}
	my $dir = shift || 't';
	unless ( -d $dir ) {
		die "tests_recursive dir '$dir' does not exist";
	}
	%test_dir = ();
	require File::Find;
	File::Find::find( \&_wanted_t, $dir );
	$self->tests( join ' ', map { "$_/*.t" } sort keys %test_dir );
}

sub write {
	my $self = shift;
	die "&Makefile->write() takes no arguments\n" if @_;

	# Make sure we have a new enough
	require ExtUtils::MakeMaker;

	# MakeMaker can complain about module versions that include

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

	# for details.

	$self->configure_requires( 'ExtUtils::MakeMaker' => $ExtUtils::MakeMaker::VERSION =~ /^(\d+\.\d+)/ );

	# Generate the
	my $args = $self->makemaker_args;
	$args->{DISTNAME} = $self->name;
	$args->{NAME}     = $self->module_name || $self->name;
	$args->{VERSION}  = $self->version;
	$args->{NAME}     =~ s/-/::/g;
	if ( $self->tests ) {
		$args->{test} = { TESTS => $self->tests };
	}
	if ($] >= 5.005) {
		$args->{ABSTRACT} = $self->abstract;
		$args->{AUTHOR}   = $self->author;
	}
	if ( eval($ExtUtils::MakeMaker::VERSION) >= 6.10 ) {
		$args->{NO_META} = 1;
	}
	if ( eval($ExtUtils::MakeMaker::VERSION) > 6.17 and $self->sign ) {
		$args->{SIGN} = 1;

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

			. $self->preamble
		: '';
	my $postamble = "# Postamble by $top_class $top_version\n"
		. ($self->postamble || '');

	local *MAKEFILE;
	open MAKEFILE, "< $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!";
	my $makefile = do { local $/; <MAKEFILE> };
	close MAKEFILE or die $!;

	$makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /;
	$makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g;
	$makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g;
	$makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m;
	$makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m;

	# Module::Install will never be used to build the Core Perl
	# Sometimes PERL_LIB and PERL_ARCHLIB get written anyway, which breaks
	# PREFIX/PERL5LIB, and thus, install_share. Blank them if they exist
	$makefile =~ s/^PERL_LIB = .+/PERL_LIB =/m;
	#$makefile =~ s/^PERL_ARCHLIB = .+/PERL_ARCHLIB =/m;

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

	@ISA     = qw{Module::Install::Base};
}

my @scalar_keys = qw{
	name
	module_name
	abstract
	author
	version
	distribution_type
	tests
	installdirs
};

my @tuple_keys = qw{
	configure_requires
	build_requires
	requires
	recommends
	bundles
	resources

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

			die("Unsupported reserved lowercase resource '$name'");
		}
		$self->{values}{resources} ||= [];
		push @{ $self->{values}{resources} }, [ $name, $value ];
	}
	$self->{values}{resources};
}

# Aliases for build_requires that will have alternative
# meanings in some future version of META.yml.
sub test_requires      { shift->build_requires(@_) }
sub install_requires   { shift->build_requires(@_) }

# Aliases for installdirs options
sub install_as_core    { $_[0]->installdirs('perl')   }
sub install_as_cpan    { $_[0]->installdirs('site')   }
sub install_as_site    { $_[0]->installdirs('site')   }
sub install_as_vendor  { $_[0]->installdirs('vendor') }

sub sign {
	my $self = shift;

lib/ASP4.pm  view on Meta::CPAN


Sends an email via L<Mail::Sendmail>.  In fact it simply calls the C<sendmail(...)> function
provided by L<Mail::Sendmail>.

Simple Example:

  $Server->Mail(
    from    => 'foo@bar.com',
    to      => 'bar@foo.com',
    subject => 'Hello, world!',
    message => 'this is a test message'
  );

To send an HTML email do the following:

  use MIME::Base64;
  $Server->Mail(
    from                        => 'foo@bar.com',
    to                          => 'bar@foo.com',
    subject                     => 'Hello, world!',
    'content-type'              => 'text/html',

lib/ASP4.pm  view on Meta::CPAN

such as in a RequestFilter - will still be there at the very end of the request -
as in a RegisterCleanup handler.

Use the C<$Stash> as a great place to store a piece of data for the duration of
a single request.

=head1 DATABASE

While ASP4 B<does not require> its users to choose any specific database (eg: MySQL or PostgreSQL)
or ORM (object-relational mapper) the B<recommended> ORM is L<Class::DBI::Lite>
since it has been completely and thoroughly tested to be 100% compatible with ASP4.

For full documentation about L<Class::DBI::Lite> please view its documentation.

B<NOTE:> L<Class::DBI::Lite> must be installed in addition to ASP4 as it is a separate library.

=head1 ASP4 QuickStart

Here is an example project to get things going.

In the C<data_connections.main> section of C<conf/asp4-config.json> you should have

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

use ASP4::UserAgent;
use ASP4::Test::Fixtures;
BEGIN { ASP4::ConfigLoader->load }

sub new
{
  my ($class) = @_;;
  
  my $config = ASP4::ConfigLoader->load;
  
  # Our test fixtures:
  my $test_data;
  if( -f $config->web->application_root . '/etc/test_fixtures.json' )
  {
    eval { require Data::Properties::JSON };
    $test_data = Data::Properties::JSON->new(
      properties_file => $config->web->application_root . '/etc/test_fixtures.json'
    ) unless $@;
  }
  elsif( -f $config->web->application_root . '/etc/test_fixtures.yaml' )
  {
    $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} }
sub properties  { shift->{properties} }
sub ua          { shift->{ua} }
sub context     { ASP4::HTTPContext->current }
sub config      { shift->{config} }
sub data        { shift->test_fixtures }    # XXX: Deprecated! - for Apache2::ASP compat only.
sub test_data   { shift->test_fixtures }    # XXX: Deprecated!

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

1;# return true:

=pod

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

  
  # Create an api object:
  my $api = ASP4::API->new;
  
  # Use the API:
  my $res = $api->ua->get('/index.asp');
  if( $res->is_success ) {
    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
  
  use strict;
  use warnings 'all';
  use Test::More 'no_plan';
  

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

=head2 config

Returns the L<ASP4::Config> object for the web application.

=head2 properties

Returns an object representing your C</etc/properties.yaml> file.

=head2 data

Returns an object representing your C</etc/test_fixtures.yaml> file.

=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

Please visit the ASP4 homepage at L<http://0x31337.org/code/> to see examples

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


our $CONFIGFILE = 'asp4-config.json';


sub config_path
{
  my $path = $CONFIGFILE;
  
  my $root = do { ($ENV{REMOTE_ADDR} || '') eq '' ? fastcwd() : $ENV{DOCUMENT_ROOT} || fastcwd() };
  
  # Try test dir:
  if( -f "$root/t/conf/$CONFIGFILE" )
  {
    return "$root/t/conf/$CONFIGFILE";
  }# end if()
  
  # Start moving up:
  for( 1...10 )
  {
    my $path = "$root/conf/$CONFIGFILE";
    return $path if -f $path;

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

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',
            'request_uri' => '/',
            'user_agent' => 'test-useragent v2.0',
            'file' => '/home/john/Projects/myapp/www/htdocs/index.asp',
            'session_data' => '{}',
            'message' => 'A fake error has occurred',
            'http_code' => '500',
            'stacktrace' => 'A fake error has occurred at /tmp/PAGE_CACHE/TSR_WWW/__index_asp.pm line 2.
  ',
            'domain' => 'www.tsr.local',
            'form_data' => '{}',
            'http_referer' => '',
            'code' => 'line 1: <h1>Hello, world!</h1>

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

Returns the current C<ASP4::Config> for the HTTP request.

=head2 cgi

Provided B<Just In Case> - returns the L<CGI> object for the HTTP request.

=head2 r

Provided B<Just In Case> - returns the L<Apache2::RequestRec> for the HTTP request.

B<NOTE:> Under L<ASP4::API> (eg: in a unit test) C<$r> will be an instance of L<ASP4::Mock::RequestRec> instead.

=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

Please visit the ASP4 homepage at L<http://0x31337.org/code/> to see examples

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



sub _parse_tag_attrs
{
  my ($s, $str) = @_;
  
  my $attr = { };
  while( $str =~ m@([^\s\=\"\']+)(\s*=\s*(?:(")(.*?)"|(')(.*?)'|([^'"\s=]+)['"]*))?@sg ) #@
  {
    my $key = $1;
    my $test = $2;
    my $val  = ( $3 ? $4 : ( $5 ? $6 : $7 ));
    if( $test )
    {
      $attr->{ lc($key) } = $val;
    }
    else
    {
      $attr->{ lc($key) } = $key;
    }# end if()
  }# end while()
  
  return $attr;

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

      ...
    },
    ...
  }

=head1 DESCRIPTION

Subclass C<ASP4::RequestFilter> to instantly apply rules to incoming
requests.

These RequestFilters also work for testing via L<ASP4::API>.

=head1 ABSTRACT METHODS

=head2 run( $self, $context )

B<IMPORTANT:> Return C<-1> (or $Response->Declined) to allow the current RequestFilter to be ignored.

Returning anything else...

  return $Response->Redirect("/unauthorized/");

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

Becomes:

  <tag/>

=head2 URLEncode( $str )

Converts a string for use within a URL.

eg:

  test@test.com

becomes:

  test%40test.com

=head2 URLDecode( $str )

Converts a url-encoded string to a normal string.

eg:

  test%40test.com

becomes:

  test@test.com

=head2 MapPath( $file )

Converts a relative path to a full disk path.

eg:

  /contact/form.asp

becomes:

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

  
  my $escaped = $cgi->escape( 'Hello world' );
  my $unescaped = $cgi->unescape( 'Hello+world' );
  
  my $upload = $cgi->upload('filename');
  
  my $filehandle = $cgi->upload_info('filename', 'filehandle' );

=head1 DESCRIPTION

This package provides basic CGI functionality and is also used for testing and
in the API enironment.

C<ASP4::SimpleCGI> uses L<HTTP::Body> under the hood.

=head1 PUBLIC METHODS

=head2 new( %args )

Returns a new C<ASP4::SimpleCGI> object.

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


=head2 RequestFilters vs TransHandlers

The difference between TransHandlers and L<ASP4::RequestFilter>s is that
within a RequestFilter, you have access to all of the normal ASP objects ($Request, $Response, $Session, etc).

In a TransHandler, you only have access to the L<Apache2::RequestRec> C<$r> and the 
L<ASP4::Config> (and only then if you load it up yourself via L<ASP4::ConfigLoader>.

B<NOTE>: - TransHandlers are configured in the C<httpd.conf> and are only executed
in a real Apache2 httpd environment.  They are not executed during testing or via
L<ASP4::API>.

TransHandlers are a handy way of jumping into "normal" mod_perl handler mode without
losing access to your web application's config.

=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/UserAgent.pm  view on Meta::CPAN

    $ENV{SCRIPT_FILENAME} = $s->config->web->www_root . $uri_no_args;
    if( -d $ENV{SCRIPT_FILENAME} )
    {
      $ENV{SCRIPT_FILENAME} =~ s{/$}{};
      $ENV{SCRIPT_FILENAME} .= "/index.asp";
    }# end if()
    $ENV{SCRIPT_NAME} = $uri_no_args;
  }# end unless()
  
  # User-Agent:
  $req->header( 'User-Agent' => 'test-useragent v2.0' );
  $ENV{HTTP_USER_AGENT} = 'test-useragent v2.0';
  
  # Cookies:
  $req->header( 'Cookie' => $ENV{HTTP_COOKIE} = $s->http_cookie );
  
  if( $ENV{REQUEST_METHOD} =~ m/^post$/i )
  { 
    # Set up the basic params:
    return ASP4::SimpleCGI->new(
      querystring     => $ENV{QUERY_STRING},
      body            => $req->content,

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

    username  => 'willy',
    password  => 'wonka',
  ]);
  
  my $res = $api->ua->upload('/handlers/file.upload', [
    foo   => 'bar',
    baz   => 'bux',
    file  => ['/home/john/avatar.jpg']
  ]);
  
  # Some form testing:
  my ($form) = HTML::Form->parse( $res->content, '/' );
  $form->find_input('username')->value('bob');
  my $res = $api->ua->submit_form( $form );
  
  # Add/remove a cookie:
  $api->ua->add_cookie( "the-boss" => "me" );
  $api->remove_cookie( "the-boss" );

=head1 DESCRIPTION

Enables unit-testing ASP4 applications by providing the ability to execuite web 
pages from your code, without a webserver.

=head1 PUBLIC METHODS

=head2 get( $url )

Calls C<$url> and returns the L<HTTP::Response> result.

=head2 post( $url, $args )

sbin/asp4-deploy  view on Meta::CPAN

my $start_cwd = cwd();

my ($id) = $src =~ m{\b/?([^/]+?\d\d\d\d\-\d\d\-\d\d_\d\d\.\d\d\.\d\d)\.tar\.gz$}
  or die "Invalid --src: '$src' does not match the standard filename.\n";
if( $target )
{
  -d $target && chdir($target)
    or die "Invalid --target: '$target': $!\n";
}# end if()

if( -d 'latest' )
{
  `rm -f deploying`;
  
  # Copy over the config files:
  `tar -zxvf "$src" && ln -s "$id" deploying`;
  my @test_errors = ( );
  foreach( grep { $_ !~ m{latest/common$} } <latest/*> )
  {
    my ($folder) = $_ =~ m{latest/([^/]+)};
    `cp -rf latest/$folder/conf/* deploying/$folder/conf/`;
    chdir("deploying/$folder");
    unless( eval { runtests( <t/*/*.t> ) } ) #/
    {
      push @test_errors, $@;
    }# end unless()
  }# end foreach()
  chdir($start_cwd);
  
  if( @test_errors )
  {
    die "Tests failed:\n", join "\n", @test_errors;
  }# end if()
  
  `rm -rf latest`;
  `rm -rf deploying`;
  `ln -s "$id" latest`;
}
else
{
  `tar -zxvf "$src" && ln -s "$id" latest`;
  my @to_update = ( );
  my @files = qw( asp4-config.json httpd.conf );
  foreach( grep { $_ !~ m{latest/common$} } <latest/*> )
  {
    my ($folder) = $_ =~ m{latest/([^/]+)};
    foreach my $file ( @files )
    {
      if( (stat("latest/$folder/conf/$file.template"))[7]  )
      {
        `cp latest/$folder/conf/$file.template latest/$folder/conf/$file`;
        push @to_update, "latest/$folder/conf/$file";
      }# end if()
    }# end foreach()
  }# end foreach()
  warn "\n\n***You must update the following configuration files:***\n";
  warn join( "\n", map {"\t* $_"} @to_update), "\n\n";
}# end if()

=pod

=head1 NAME

sbin/asp4-deploy  view on Meta::CPAN


Copies all the C<conf/*.template> files to be non-template files.

eg:

  cp conf/asp4-config.json.template conf/asp4-config.json
  cp conf/httpd.conf.template conf/httpd.conf

=item Step 3

Makes a symbolic link from C</the/target/path/latest/> to C</the/target/path/MyWeb_2011-11-15_23.59.39>.

=item Step 4

You update your C<conf/asp4-config.json> and C<conf/httpd.conf> to work for the new environment.

You run your tests:

  prove -r t/

If everything checks out, then you update your server's other configuration (eg: /etc/apache2/sites-enabled/*) to include:

  /the/target/path/latest/www/conf/httpd.conf

B<Restart apache and you're done.>

=back

=head2 Subsequent Deployments

Subsequent deployments are easier for us humans, but more work for the computers.

=over 4

sbin/asp4-deploy  view on Meta::CPAN

=item Step 2

Creates a symbolic link 'C<deploying>' in your project folder.

eg:

  /var/www/myweb/deploying  ->  /var/www/myweb/MyWeb_2011-11-15_23.59.39

=item Step 3

Copies all your configuration files from 'C<latest/*/conf/*>' into 'C<deploying/*/conf/*>'

=item Step 4

Runs unit tests on all folders under deploying except for 'C<common>'.

If all tests pass, we continue.  Otherwise, we bail out with errors.

=item Step 5

Unlink the C<deploying> symbolic link and change C<latest> to point to the new directory.

=item Step 6

B<After a successful deployment, you should restart apache.>

=back

=head1 DEPLOYMENT DIRECTORY FOLDER STRUCTURE

Initially you will have a folder structure like this:

  .
  |-- MyWeb_2011-10-28_15.37.55
  `-- latest -> MyWeb_2011-10-28_15.37.55

After several deployments, it will look like this:

  .
  |-- MyWeb_2011-10-28_15.37.55
  |-- MyWeb_2011-10-28_16.04.35
  |-- MyWeb_2011-10-29_23.55.55
  |-- MyWeb_2011-10-29_23.59.39
  |-- MyWeb_2011-10-30_00.00.13
  `-- latest -> MyWeb_2011-10-30_00.00.13

If you need to rollback to a previous release, simply update the symbolic link
so that it points to a previous version.

  rm latest
  ln -s MyWeb_2011-10-29_23.59.39 latest

=head1 GNU/LINUX, POSIX OS ONLY

This tool makes use of symbolic links and the GNU tools to Get The Job Done.

If your operating system doesn't provide them, consider upgrading to one that does.

=head1 BUGS

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

sbin/asphelper  view on Meta::CPAN

  like \$res->content, qr(visited this page \$_ time), "Simple session counter: \$_ visits recorded.";
  \$res = \$api->ua->get("/");
}# end for()

TEST
  }# end if()


    print $ofh <<"TEST";

# More tests can go here or in other files.

TEST
  close($ofh);
}# end unless()

warn "="x60, "\n";
warn "    Running Initial Test Suite...\n";
warn "="x60, "\n";
chdir("www");
`asp4 /` =~ m{You have visited this page}

sbin/asphelper  view on Meta::CPAN


  asphelper --app=AppName --domain=example.com --email=you@your-email.com [--host=dbhost --db=dbname  --user=dbusername]

If you specify C<--dbname> and C<--dbuser> it will ask you for a database password - completely optional.

=head1 DESCRIPTION

The C<asphelper> program offers a way to get up-and-running quickly with a new ASP4 web application.

After successfully answering its questions, C<asphelper> will generate a skeleton web application
including config files, full directory structure and a simple unit test.

Use the resulting application as a starting-point for your own development.

If executed with the following arguments:

  asphelper --app=Foo --domain=www.foo.local --email=foo@bar.com --host=localhost --db=foo --user=root

You will get an application matching what is listed below:

  .

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

  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

my $sth = $dbh->prepare("SELECT * FROM asp_sessions WHERE session_id = ?");
$sth->execute( $id );
ok( my $rec = $sth->fetchrow_hashref, "fetched record" );
$sth->finish();

$dbh->disconnect();


t/010-basic/090-everything.t  view on Meta::CPAN

use ASP4::API;

my $api = ASP4::API->new;

ok( my $res = $api->ua->get('/everything/step01.asp'), "Got res");

ok(
  $res = $api->ua->get('/handlers/dev.headers'), "Got headers res again"
);
is(
  $res->header('content-type') => 'text/x-test'
);
is(
  $res->header('content-length') => 3000
);
is(
  $res->content => "X"x3000
);

# static:
{

t/030-filters/010-seo.t  view on Meta::CPAN

#!/usr/bin/perl -w

use strict;
use warnings 'all';
use ASP4::API;
use Test::More tests => 5;
my $api; BEGIN { $api = ASP4::API->new }

ok( $api, "Got api");

my $res = $api->ua->get("/seo/123/");

ok( $res->is_success, "request is successful" );

is( $res->content => 'Hello - SEO
', "Got the content we were expecting");

t/etc/test_fixtures.json  view on Meta::CPAN

{
  "contact_form": {
    "first_name": "John",
    "last_name":  "Doe",
    "email":      "john.doe@test.com",
    "message":    "This is a test message...just a test."
  }
}

t/etc/test_fixtures.yaml  view on Meta::CPAN

---
  contact_form:
    first_name: John
    last_name:  Doe
    email:      john.doe\@test.com
    message:    This is a test message...just a test.

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

package dev::encoding::hello;

use strict;
use warnings 'all';
use base 'ASP4::FormHandler';
use vars __PACKAGE__->VARS;
use MIME::Base64;
use Encode;
use utf8;

# TODO: Encoding tests to make sure we get round-trip encoding integrity.
sub run
{
  my ($s, $context) = @_;
  
  my $hellos = {
    arabic  => {
      original  => 'مرحبا ، العالم!',
      encoded => 'JiMxNjA1OyYjMTU4NTsmIzE1ODE7JiMxNTc2OyYjMTU3NTsgJiMxNTQ4OyAmIzE1NzU7JiMxNjA0
OyYjMTU5MzsmIzE1NzU7JiMxNjA0OyYjMTYwNTsh'
    },

t/handlers/dev/headers.pm  view on Meta::CPAN


use strict;
use warnings 'all';
use base 'ASP4::FormHandler';
use vars __PACKAGE__->VARS;

sub run
{
  my ($s, $context) = @_;
  
  $Response->ContentType("text/x-test");
  $Response->Expires( 500 );
  $Response->AddHeader("content-length" => 3000);
  $Response->Write( "X"x3000 );
  $Response->Flush;
}# end run()

1;# return true:

t/htdocs/pageparser/010.asp  view on Meta::CPAN

<%@ MasterPage %>
 
<asp:ContentPlaceHolder id="test01" />
<asp:ContentPlaceHolder id="test02" />
<asp:ContentPlaceHolder id="test03" />



( run in 0.834 second using v1.01-cache-2.11-cpan-87723dcf8b7 )