ASP4
view release on metacpan or search on metacpan
was changed - and if it has been more than 60 seconds, the session is saved
and the __lastMod value is updated to time() - thus preventing expiry of
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
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
had been updated.
lib/ASP4/PageParser.pm view on Meta::CPAN
# It's an "end" tag: </asp:ContentPlaceHolder>
my $item = pop(@stack);
$depth--;
my $repl = $item->{end_tag};
$$ref =~ s{$tag}{$repl}s;
unshift @placeholder_tags, $item;
}
else
{
# It's a "start" tag: <asp:ContentPlaceHolder id="...">
my ($id) = $tag =~ m{<asp:ContentPlaceHolder\s+id\="(.+?)">}is;
push @stack, {
ident => $ident,
id => $id,
depth => $depth++,
line => $s->_tag_line_number( $tag ),
start_tag => '______INP_' . sprintf('%03d',$ident) . '______',
end_tag => '______OUTP_' . sprintf('%03d',$ident) . '______'
};
$ident++;
my $repl = $stack[-1]->{start_tag};
$$ref =~ s{\Q$tag\E}{$repl}s;
}# end if()
}# end foreach()
};
foreach my $tag ( sort {$b->{depth} <=> $a->{depth} } @placeholder_tags )
{
my $start = $tag->{start_tag};
my $end = $tag->{end_tag};
my ($contents) = $$ref =~ m{$start(.*?)$end}s;
$tag->{contents} = "\$Response->Write(q~$contents~);";
$$ref =~ s{$start\Q$contents\E$end}{\~); \$__self->$tag->{id}(\$__context); if( \$__context->did_end() ){\$__context->response->Clear(); return; } \$Response->Write(q\~}s;
}# end foreach()
# The <asp:Content PlaceHolderID="...">...</asp:Content> tags:
my @content_tags = ( );
CONTENT: {
my @stack = ( );
foreach my $tag ( $$ref =~ m{(<asp:Content\s+PlaceHolderID\=".+?"\s*>|</asp:Content\s*>)}gis )
{
if( $tag =~ m{^</} )
{
# It's an "end" tag: </asp:Content>
my $item = pop(@stack);
$depth--;
my $repl = $item->{end_tag};
$$ref =~ s{\Q$tag\E}{$repl}s;
}
else
{
# It's a "start" tag: <asp:Content PlaceHolderID="...">
my ($id) = $tag =~ m{<asp:Content\s+PlaceHolderID\="(.+?)"\s*>}is;
push @stack, {
ident => $ident,
id => $id,
depth => $depth++,
line => $s->_tag_line_number( $tag ),
start_tag => '______INC_' . sprintf('%03d',$ident) . '______',
end_tag => '______OUTC_' . sprintf('%03d',$ident) . '______'
};
$ident++;
my $repl = $stack[-1]->{start_tag};
$$ref =~ s{\Q$tag\E}{$repl}s;
unshift @content_tags, $stack[-1];
}# end if()
}# end foreach()
};
foreach my $tag ( sort {$b->{depth} <=> $a->{depth} } @content_tags )
{
my $start = $tag->{start_tag};
my $end = $tag->{end_tag};
my ($contents) = $$ref =~ m{$start(.*?)$end}s;
$tag->{contents} = "\$Response->Write(q~$contents~);";
$$ref =~ s{$start\Q$contents\E$end}{\~); \$__self->$tag->{id}(\$__context); if( \$__context->did_end() ){\$__context->response->Clear(); return; } \$Response->Write(q\~}s;
}# end foreach()
my $code = <<"CODE";
package $s->{package};
use strict;
use warnings 'all';
no warnings 'redefine';
use base '$s->{base_class}';
use vars __PACKAGE__->VARS;
lib/ASP4/SessionStateManager.pm view on Meta::CPAN
SELECT count(*)
FROM asp_sessions
WHERE session_id = ?
$sth->execute( $id );
($is_active) = $sth->fetchrow();
$sth->finish();
}
else
{
my $range_start = time() - ( $timeout * 60 );
local $s->db_Session->{AutoCommit} = 1;
my $sth = $s->db_Session->prepare(<<"");
SELECT count(*)
FROM asp_sessions
WHERE session_id = ?
AND modified_on - created_on < ?
$sth->execute( $id, $timeout );
($is_active) = $sth->fetchrow();
$sth->finish();
sbin/asp4-deploy view on Meta::CPAN
use Test::Harness;
use Cwd 'cwd';
my $res = GetOptions(
"src=s" => \my $src,
"target=s" => \my $target
);
$src or die "Usage: $0 --src=</path/to/MyApp_2011-11-29_12.03.34.tar.gz> [--target=/var/www/appname/]\n";
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' )
sbin/asp4-deploy view on Meta::CPAN
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`;
}
sbin/asp4-deploy view on Meta::CPAN
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
=item Step 1
sbin/asp4-deploy view on Meta::CPAN
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
sbin/asphelper view on Meta::CPAN
# Talk about the config now:
warn <<"END";
!!!!!!!!!!!!!!!!!!!!!! CONGRATULATIONS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*** Update your Apache Config ***
Include $cwd/www/conf/httpd.conf
*** Add This to your /etc/hosts File ***
127.0.0.1 $domain
*** Restart Apache ***
Maybe: sudo /etc/init.d/httpd restart
Or: sudo /etc/init.d/apache2 restart
Or: service apache2 restart
*** To Test it in Your Browser ***
Navigate to http://$domain
*** To Run the Unit Tests ***
cd $cwd/www
prove -rv t
*** To Run an ASP Script From the Command Line ***
cd $cwd/www
sbin/asphelper view on Meta::CPAN
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:
.
`-- foo
|-- common
t/020-bench/010-hello.t view on Meta::CPAN
warn "GET /pageparser/child-inner2.asp 1000 times in $time seconds ($persec/second)\n";
}
{
my ($time, $persec) = bench('/masters/deep.asp', 1000);
warn "GET /masters/deep.asp 1000 times in $time seconds ($persec/second)\n";
}
sub bench {
my ($uri, $times) = @_;
my $start = gettimeofday();
for( 1..$times ) {
$api->ua->get($uri)->is_success or die "ERROR";
}
my $diff = gettimeofday() - $start;
my $persec = $times / $diff;
return ($diff, $persec);
}
( run in 0.404 second using v1.01-cache-2.11-cpan-0d8aa00de5b )