NAME

Eve::Registry - a service provider class.

SYNOPSIS

my $registry = Eve::Registry->new(
    # some literals declarations);

my $service = $registry->get_service();

DESCRIPTION

Eve::Registry is the class that provides all services that are required by the application and manages their dependencies.

Constructor arguments

working_dir_string
base_uri_string
alias_base_uri_string_list

an optional base URI alias string list

email_from_string
pgsql_database
pgsql_host
pgsql_port
pgsql_user
pgsql_password
pgsql_schema
session_expiration_interval

an interval of idling from the last access when the session is considered actual (0 cancels expiration), 30 days is set by default,

template_path
template_compile_path
template_expiration_interval
template_var_hash

a hash of variables that will be made available for the templates.

the pgsql_* literals except pgsql_schema are undef by default so an attempt will be made to use standard PostgreSQL environment variables. For the pgsql_schema the default 'public' value will be used.

METHODS

init()

SERVICES

The registry's purpose is to provide different services, which can be simple literals as well as lists, hashes and objects. For objects there are two types of services: lazy loader and prototype:

Lazy loader

A lazy loader service is a service that creates the object it provides upon first request. All subsequent requests of this service will return the same object that was created the first time.

use Eve::Registry;

sub first_sub {
    my $registry = Eve::Registry->new();
    my $lazy_service = $registry->get_lazy_service();

    $lazy_service->set_state(true);
}

sub second_sub {
    my $registry = Eve::Registry->new();
    my $lazy_service = $registry->get_lazy_service();

    # Returns state set in previous sub
    print $lazy_service->get_state();
}

Prototype

A prototype service is a service that creates the provided object each time it is requested.

use Eve::Registry;

sub third_sub {
    my $registry = Eve::Registry->new();
    my $first_service = $registry->get_proto_service();
    my $second_service = $registry->get_proto_service();

    if ($first_service eq $second_service) {
        die("This will never get executed");
    }
}

lazy_load()

Creates a service object if it hasn't been created and returns it. Otherwise returns a stored copy of a previously service object.

Arguments

name

A unique name for a service,

code

A code reference that must create and return the service object.

get_uri()

A URI prototype service.

Arguments

string

a URI string that will be used to create a new URI object.

get_base_uri()

A base URI prototype service.

get_alias_base_uri_list()

A list of alias base URIs prototype service.

get_http_request()

An HTTP request lazy loader service.

get_http_response()

An HTTP response lazy loader service.

get_event_map()

An event map lazy loader service.

get_email()

A mailer lazy loader service.

get_http_dispatcher()

An HTTP resource dispatcher lazy loader service.

get_http_output()

An HTTP output lazy service.

get_template()

A Template lazy loader service.

get_template_var_hash()

A lazy template hash getter service.

get_session()

A persistent session prototype service.

Arguments

id

a session identifier md5 string

get_pgsql()

A PostgreSQL registry lazy loader service.

get_json()

A JSON converter adapter class lazy loader service.

add_binding

A shorthand method for binding resources to specific URI patterns. Accepts arguments as a simple list, which are resource binding name, pattern and constructor code reference. The fourth argument is a hash reference that is added to the bind method call.

bind_http_event_handlers()

Binds HTTP event handlers for standard request/response functionality.

SEE ALSO

Eve::Email
Eve::EventHandler::ExternalSignup
Eve::EventMap
Eve::HttpOutput
Eve::HttpRequest
Eve::HttpDispatcher
Eve::HttpResource
Eve::HttpResource::Template
Eve::HttpResponse
Eve::Json
Eve::Model::Authentication
Eve::PgSql
Eve::Session
Eve::Template
Eve::Uri

LICENSE AND COPYRIGHT

Copyright 2012 Igor Zinovyev.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

AUTHOR

Sergey Konoplev
Igor Zinovyev