ASP4

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN


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
  - Now both POST'ed and GET'ed parameters are added to $Form.  This means that if
    you...
    <form action="/page/?foo=abc" method="post"><input name="bar" value="123" /></form>
    ...both foo=abc and bar=123 will be in $Form.  Before this update, only bar=123 would
    be there, and foo=abc would be lost.

2010-04-06    v1.025
  - If Router::Generic is installed, ASP4::ConfigNode::Web will create $Config->web->router
    based on the "routes" segment of asp4-config.json.
  - No documentation about this yet.

2010-03-22    v1.024
  - $Request->Reroute() with additional querystring parameters was not adding

README.markdown  view on Meta::CPAN

      

      # Our validation errors:
      my $errors = $Session->{validation_errors} || { };
      $::err = sub {
        my $field = shift;
        my $error = $errors->{$field} or return;
        %><span class="field_error"><%= $Server->HTMLEncode( $error ) %></span><%
      };
    %>
    <form id="register_form" method="post" action="/handlers/myapp.register">
      <p>
        <label>Email:</label>
        <input type="text" name="email" value="<%= $Server->HTMLEncode( $Form->{email} ) %>" />
        <% $::err->("email"); %>
      </p>
      <p>
        <label>Password:</label>
        <input type="password" name="password" />
        <% $::err->("password"); %>
      </p>

README.markdown  view on Meta::CPAN

        <span class="date"><%= $msg->created_on %></span>
      </div>
    <%
      }# end foreach()
    %>
    </div>
    

    <div style="float: right; width: 40%; border: dotted 1px #000;">
      <h3>Send New Message</h3>
      <form id="send_form" method="post" action="/handlers/app.send">
        <p>
          <label>Recipient:</label>
          <select name="to_user_id">
    <%
      my @users = App::db::user->search_where({
        user_id => {'!=' => $user->id }
      }, {
        order_by => "email"
      });
      foreach my $user ( @users ) {

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

sub fix_up_makefile {
	my $self          = shift;
	my $makefile_name = shift;
	my $top_class     = ref($self->_top) || '';
	my $top_version   = $self->_top->VERSION || '';

	my $preamble = $self->preamble
		? "# Preamble by $top_class $top_version\n"
			. $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;

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

	$makefile =~ s/^PERL_LIB = .+/PERL_LIB =/m;
	#$makefile =~ s/^PERL_ARCHLIB = .+/PERL_ARCHLIB =/m;

	# Perl 5.005 mentions PERL_LIB explicitly, so we have to remove that as well.
	$makefile =~ s/(\"?)-I\$\(PERL_LIB\)\1//g;

	# XXX - This is currently unused; not sure if it breaks other MM-users
	# $makefile =~ s/^pm_to_blib\s+:\s+/pm_to_blib :: /mg;

	open  MAKEFILE, "> $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!";
	print MAKEFILE  "$preamble$makefile$postamble" or die $!;
	close MAKEFILE  or die $!;

	1;
}

sub preamble {
	my ($self, $text) = @_;
	$self->{preamble} = $text . $self->{preamble} if defined $text;
	$self->{preamble};
}

sub postamble {
	my ($self, $text) = @_;
	$self->{postamble} ||= $self->admin->postamble;
	$self->{postamble} .= $text if defined $text;
	$self->{postamble}
}

1;

__END__

#line 379

lib/ASP4.pm  view on Meta::CPAN

    }
    
    # Our validation errors:
    my $errors = $Session->{validation_errors} || { };
    $::err = sub {
      my $field = shift;
      my $error = $errors->{$field} or return;
      %><span class="field_error"><%= $Server->HTMLEncode( $error ) %></span><%
    };
  %>
  <form id="register_form" method="post" action="/handlers/myapp.register">
    <p>
      <label>Email:</label>
      <input type="text" name="email" value="<%= $Server->HTMLEncode( $Form->{email} ) %>" />
      <% $::err->("email"); %>
    </p>
    <p>
      <label>Password:</label>
      <input type="password" name="password" />
      <% $::err->("password"); %>
    </p>

lib/ASP4.pm  view on Meta::CPAN

      <div class="body"><%= $Server->HTMLEncode( $msg->body ) %></div>
      <span class="date"><%= $msg->created_on %></span>
    </div>
  <%
    }# end foreach()
  %>
  </div>
  
  <div style="float: right; width: 40%; border: dotted 1px #000;">
    <h3>Send New Message</h3>
    <form id="send_form" method="post" action="/handlers/app.send">
      <p>
        <label>Recipient:</label>
        <select name="to_user_id">
  <%
    my @users = App::db::user->search_where({
      user_id => {'!=' => $user->id }
    }, {
      order_by => "email"
    });
    foreach my $user ( @users ) {

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

  }# end foreach()

=head1 JSON Config File

ASP4::ASP keeps all of its configuration inside of C</conf/asp4-config.json>

Here is an example:

  {
    "system": {
      "post_processors": [
        
      ],
      "libs": [
        "@ServerRoot@/lib",
        "@ProjectRoot@/lib"
      ],
      "load_modules": [
        "DBI",
        "DBD::SQLite"
      ],

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



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


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:

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

=head1 PUBLIC PROPERTIES

=head2 libs

A list of library paths that should be included into C<@INC>.

=head2 load_modules

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

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

  return bless { }, $class;
}# end new()


sub parse
{
  my ($s, $doc, $root) = @_;
  
  my $config = ASP4::Config->new( $doc, $root );
  
  # Now do any post-processing:
  foreach my $class ( $config->system->post_processors )
  {
    (my $file = "$class.pm") =~ s/::/\//;
    require $file unless $INC{$file};
    $config = $class->new()->post_process( $config );
  }# end foreach()
  
  return $config;
}# end parse()

1;# return true:

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



sub new
{
  my ($class, %args) = @_;
  
  return bless \%args, $class;
}# end new()


sub post_process($$);

1;# return true:

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

}# end run()


sub send_error
{
  my ($s, $error) = @_;
  
  $ua ||= LWP::UserAgent->new();
  $ua->agent( ref($s) . " $ASP4::VERSION" );
  my %clone = %$error;
  my $req = POST $Config->errors->post_errors_to, \%clone;
  $ua->request( $req );
}# end send_error()

1;# return true:

=pod

=head1 NAME

ASP4::ErrorHandler::Remote - Send your errors someplace else via http.

=head1 SYNOPSIS

In your C<asp4-config.json>:

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

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

  line 4: %>
  ',
            'line' => '2'
  };


=head1 PUBLIC METHODS

=head2 send_error( $error )

Sends the error data to the web address specified in C<<$Config->errors->post_errors_to>>.

The field names and values will correspond to the properties of an C<ASP4::Error> object.

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

    my $txt = $1; '~);' . $txt . ';$Response->Write(q~'
  }gxse;
  
  $$ref =~ s/(\$Response\->End)/return $1/gs;
  
  $$ref = ';$Response->Write(q~' . $$ref . '~);';
  
  # Now do the final ~ substitution:
  $$ref =~ s{(\(q~)(.*?)(~\);)}{
    my $pre = $1;
    my $post = $3;
    (my $txt = $2) =~ s/~/\\~/g;
    "$pre$txt$post"
  }xsge;
}# end _parse_scriptlet_tags()


sub _get_directives
{
  my ($s) = @_;
  
  my $ref = $s->source_code;
  my %directives = ( );

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

  $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} );
  
  $args ||= [ ];
  my $req = POST $uri, $args;
  my $referer = $ENV{HTTP_REFERER};
  %ENV = (
    %{ $s->{env} },

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

  );
  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} );
  
  $args ||= [ ];
  my $req = POST $uri, Content_Type => 'form-data', Content => $args;

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

    $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,
      content_type    => $req->headers->{'content-type'},
      content_length  => $req->headers->{'content-length'},
    );
  }
  else

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

=head1 NAME

ASP4::UserAgent - Execute ASP4 requests without a web server.

=head1 SYNOPSIS

B<NOTE:> 99.99% of the time you will access this via L<ASP4::API>.

  my HTTP::Response $res = $api->ua->get('/index.asp?foo=bar');
  
  my $res = $api->ua->post('/handlers/user.login', [
    username  => 'willy',
    password  => 'wonka',
  ]);
  
  my $res = $api->ua->upload('/handlers/file.upload', [
    foo   => 'bar',
    baz   => 'bux',
    file  => ['/home/john/avatar.jpg']
  ]);
  

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


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 )

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

=head2 upload( $url, $args )

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

=head2 submit_form( HTML::Form $form )

Submits the C<$form> and returns the L<HTTP::Response> result.

sbin/asphelper  view on Meta::CPAN


  if( $CDBIL_Version )
  {
print $ofh <<"MORE";
@{[ $dbName ? qq(use_ok('$appName\::db::model');) : '' ]}
MORE
  }# end if()
  
  print $ofh <<"TEST";

my \$res = \$api->ua->post("/handlers/$hClass.www.echo", {
  hello => "world"
});
like \$res->content, qr('hello'\\s+\\=\>\\s+'world'), "/handlers/$hClass.www.echo?hello=world works";

ok( \$res = \$api->ua->get("/"), "Got '/'.");
ok( \$res->is_success, "GET / is successful.");
ok( \$res->content, "Got some content also.");


TEST

sbin/asphelper  view on Meta::CPAN

END


sub generic_config
{
  my ($has_db) = @_;

  my $str = <<'EOF';
{
  "system": {
    "post_processors": [
    ],
    "libs": [
      "@ServerRoot@/lib",
      "@ProjectRoot@/common/lib"
    ],
    "load_modules": [
    ],
    "env_vars": {
    },
    "settings": {

t/010-basic/050-useragent.t  view on Meta::CPAN

  my $res = $ua->get('/useragent/hello-world.asp');
  is( $res->content, "Hello, World!\n"x5 . "\n", "hello-word.asp is correct" );
};

TEST2: {
  my $res = $ua->get('/useragent/simple-args.asp?color=red');
  is( $res->content, "Your favorite color is red!\n", "simple-args.asp is correct" );
};

TEST3: {
  my $res = $ua->post('/useragent/simple-args.asp?color=red');
  is( $res->content, "Your favorite color is red!\n", "simple-args.asp is correct" );
};

TEST4: {
  my $res = $ua->post('/useragent/simple-args.asp', {
    color => 'red'
  });
  is( $res->content, "Your favorite color is red!\n", "simple-args.asp is correct" );
};

TEST5: {
  my $res = $ua->post('/useragent/simple-args.asp', [
    color => 'red'
  ]);
  is( $res->content, "Your favorite color is red!\n", "simple-args.asp is correct" );
};

TEST6: {
  my $res = $ua->get('/useragent/simple-form.asp');
  my ($form) = HTML::Form->parse( $res->content, '/' );
  ok( $form, 'found form' );
  $form->find_input('color')->value('Red');

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

{
  "system": {
    "post_processors": [
      
    ],
    "libs": [
      "@ServerRoot@/lib"
    ],
    "load_modules": [
      "DBI",
      "DBD::SQLite"
    ],
    

t/htdocs/form.pm  view on Meta::CPAN

use vars __PACKAGE__->VARS;


handle get => sub {
  my ($s, $context) = @_;
  
  $Response->Write("Requested via 'GET'");
};


handle post => sub {
  my ($s, $context) = @_;
  
  $Response->Write("Requested via 'POST'");
};


1;# return true:

t/htdocs/useragent/simple-form.asp  view on Meta::CPAN

<html>
<body>
<form name="form1" action="/useragent/simple-form.asp" method="post">
  Color: <input type="text" name="color" value="<%= $Server->HTMLEncode( $Form->{color} ) %>" ><br>
  Pet's Name: <input type="text" name="pet_name" value="<%= $Server->HTMLEncode( $Form->{pet_name} ) %>"><br>
  <br>
  <input type="submit" value="Submit" >
</form>
</body>
</html>

t/htdocs/useragent/upload-form.asp  view on Meta::CPAN

%>
<form name="form1">
<%= $file->FileName %> -- <%= $file->FileExtension %> -- <%= $file->FileSize %><br/>
<textarea name="file_contents"><%= $file->FileContents %></textarea>
</form>
<%
  }
  else
  {
%>
<form name="form1" action="/useragent/upload-form.asp" method="post" enctype="multipart/form-data">
  <input type="file" name="filename">
  <br>
  <input type="submit" value="Submit" >
</form>
<%
  }# end if()
%>
</body>
</html>



( run in 0.992 second using v1.01-cache-2.11-cpan-ceb78f64989 )