NAME
Whatbot::Command::Role::Web - Provide web endpoints for your Command
SYNOPSIS
package Whatbot::Command::Example;
use Moose;
BEGIN { extends 'Whatbot::Command'; with 'Whatbot::Command::Role::Web'; }
sub register {
my ($self) = @_;
$self->require_direct(0);
$self->web( '/example', \&example );
}
sub example {
my ( $self, $httpd, $req ) = @_;
my $id = $req->parm('id');
$req->respond( 'content' => [ 'text/html', $out ] );
return;
}
DESCRIPTION
Whatbot::Command::Role::Web provides the ability to define web endpoints in your Command. To do this, one or more endpoints must be defined in the register() method of your command, that correspond to subroutines in the class.
A subroutine that responds to an endpoint expects three arguments: $self, which is your Command instance, $httpd, which is the AnyEvent::HTTPD object that answered the request, and $req, which is the request as a AnyEvent::HTTPD::Request.
For easier responses, you may also want to check out Whatbot::Command::Role::Template and Whatbot::Command::Role::BootstrapTemplate.
PUBLIC METHODS
- web( $path, \&callback )
-
Set up a web endpoint, used within the register() function. The first parameter is a path to respond to after the hostname and port of the request. Note that the first path registered wins, so choose your paths carefully. The second parameter is a callback when a request is received. Three parameters are sent to the callback: $self, which is your command's instance, $httpd, which is an AnyEvent::HTTPD object, and $req, which is a AnyEvent::HTTPD::Request object.
- web_url()
-
Returns the URL that the web server is currently responding to.
LICENSE/COPYRIGHT
Be excellent to each other and party on, dudes.