Apache2-Ajax

 view release on metacpan or  search on metacpan

lib/Apache2/Ajax.pm  view on Meta::CPAN

    return Apache2::Const::OK;
  }

=head1 mod_perl handler

The mod_perl response handler used must use
I<Apache2::Ajax>, and has the following general form:

  package Apache2::MyAjaxApp
  use Apache2::Ajax;
  # use whatever else
  
  sub perl_function_name {
    my @params = @_;
    # do whatever
    return $return_value;
  }
  
  sub Show_Form_sub {
    my $html = '';
    # construct html string
    return $html;
  }
  
  sub handler {
    my $r = shift;
    # do stuff
    my $ajax = Apache2::Ajax->new($r, %new_args);
    $r->print($ajax->build_html(%build_args));
    return Apache2::Const::OK;
  }

Apache2::Ajax makes available the following.

=head2 Methods

=over

=item my $ajax = Apache2::Ajax->new($r, %new_args);

The I<new()> method creates an I<Apache2::Ajax> object,
and takes a mandatory argument of
the L<Apache2::RequestRec> object I<$r>.
It can also accept an optional set of arguments,
in the form of a hash, specifying
the mapping of Perl subroutines to the automatically-generated
JavaScript functions:

    my $ajax = Apache2::Ajax->new($r, 'JSFUNC' => \&PERLFUNC);

or, using a coderef:

    my $ajax = Apache2::Ajax->new($r, 'JSFUNC' => $perlfunc);

This mapping can alternatively be done through the Apache
configuration directive I<PJX_fn>, to be described below.

=item * my $html = $ajax-E<gt>build_html(%build_args);

This returns the HTML used for the web page, either the
complete html for the whole page or the updated html;
this corresponds to the I<build_html()> method of
L<CGI::Ajax>. This method also accepts optional
arguments, in the form of a hash, of two types:

=over

=item * header =E<gt> $header

By default, the only header Apache2::Ajax sets is
the I<Content-Type>, for which I<text/html> is used.
If additional headers are required, they may
be passed as an optional argument in the
form of a hash reference, as in

  my $header = {'Content-Type' => 'text/html; charset=utf-8',
		'X-err_header_out' => 'err_headers_out',
	       };
  my $ajax = Apache2::Ajax->new($r);
  my $html = $ajax->build_html(header => $header);

=item * html =E<gt> \&Show_form

This option specifies the subroutine
provided which generates the html for the web page:

  my $ajax = Apache2::Ajax->new($r);
  $r->print($ajax->build_html(html => \&Show_form));

A coderef or a string containing the raw html can also be used.
This subroutine can alternatively be specified through
the I<PJX_html> Apache configuration directive, to be
described below.

=back

=item * my $js =  $ajax-E<gt>show_javascript();

This returns the javascript needed to be
inserted into the calling scripts html I<E<lt>headE<gt>> section;
this corresponds to the I<show_javascript()> method of
L<CGI::Ajax>.

=item * my $pjx = $ajax-E<gt>pjx;

This returns the L<CGI::Ajax> object created with the I<new> method.

=item * my $r = $ajax-E<gt>r;

This returns the L<Apache2::RequestRec> object passed into
the I<new> method.

=item * my $cgi = $ajax-E<gt>cgi;

This returns the CGI.pm-compatible object used to
supply the I<param()>, I<header()>, I<remote addr()>,
and I<url()> methods needed by L<CGI::Ajax>.

=item * my $html_ref = $ajax-E<gt>html;

This returns a reference to the subroutine specified by the



( run in 0.830 second using v1.01-cache-2.11-cpan-5a3173703d6 )