Articulate

 view release on metacpan or  search on metacpan

lib/Articulate/Service.pm  view on Meta::CPAN

package Articulate::Service;
use strict;
use warnings;

use Articulate::Syntax;

# The following provide objects which must be created on a per-request basis
use Articulate::Request;
use Articulate::Response;

use Moo;

with 'Articulate::Role::Service';
use Try::Tiny;
use Scalar::Util qw(blessed);

use Exporter::Declare;
default_exports qw(articulate_service);

=head1 NAME

Articulate::Service - provide an API to all the core Articulate
features.

=cut

=head1 DESCRIPTION

The Articulate Service provides programmatic access to all the core
features of the Articulate app. It is the intermediary between the
B<routes> and all other B<components>.

Mostly, you will want to be calling the service in routes, for
instance:

  get 'zone/:zone_name/article/:article_name' => sub {
    my ($zone_name, $article_name) = param('zone_name'), param('article_name');
    return $self->process_request ( read => "/zone/$zone_name/article/$article_name' )
  }

However, you may also want to call it from one-off scripts, tests,
etc., especially where you want to perform tasks which you don't want
to make available in routes, or where you are already in a perl
environment and mapping to the HTTP layer would be a distraction. In
theory you could create an application which did not have any web
interface at all using this service, e.g. a command-line app on a
shared server.

=cut

sub articulate_service {
  __PACKAGE__->new(@_);
}

has providers => (
  is      => 'rw',
  default => sub { [] },
  coerce  => sub { instantiate_array(@_) },
);

=head3 process_request

  my $response = service->process_request($request);
  my $response = service->process_request($verb => $data);

This is the primary method of the service: Pass in an
Articulate::Request object and the Service will produce a Response
object to match.

Alternatively, if you pass a string as the first argument, the request
will be created from the verb and the data.

Which verbs are handled, what data they require, and how they will be
processed are determined by the service providers you have set up in



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