| 1 | package EntityModel::Web; | ||||||||||
| 2 | 5 | ▶ | use EntityModel::Class { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 5 | _isa => [qw(EntityModel::Plugin)], | |||||||||
| 4 | site => { type => 'array', subclass => 'EntityModel::Web::Site' }, | ||||||||||
| 5 | 5 | }; | |||||||||
| 6 | |||||||||||
| 7 | 5 | our $VERSION = '0.004'; | |||||||||
| 8 | |||||||||||
| 9 | =head1 NAME | ||||||||||
| 10 | |||||||||||
| 11 | EntityModel::Web - website support for L<EntityModel> | ||||||||||
| 12 | |||||||||||
| 13 | =head1 VERSION | ||||||||||
| 14 | |||||||||||
| 15 | version 0.004 | ||||||||||
| 16 | |||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||
| 18 | |||||||||||
| 19 | =head1 DESCRIPTION | ||||||||||
| 20 | |||||||||||
| 21 | Support for L<EntityModel>-backed websites. Currently an early preview release, so if you're looking for a | ||||||||||
| 22 | good, production-quality web framework try something from the <L/SEE ALSO> list. | ||||||||||
| 23 | |||||||||||
| 24 | Accepts a definition for site + page hierarchy, and applies handlers as required to convert incoming requests | ||||||||||
| 25 | into outgoing responses. | ||||||||||
| 26 | |||||||||||
| 27 | The following classes provide most of the key functionality: | ||||||||||
| 28 | |||||||||||
| 29 | =over 4 | ||||||||||
| 30 | |||||||||||
| 31 | =item * L<EntityModel::Web::Request> - abstraction for an incoming HTTP/HTTPS request, may be subclassed by the | ||||||||||
| 32 | appropriate server layer. | ||||||||||
| 33 | |||||||||||
| 34 | =item * L<EntityModel::Web::Response> - abstraction for outgoing HTTP/HTTPS response | ||||||||||
| 35 | |||||||||||
| 36 | =item * L<EntityModel::Web::Site> - website definition | ||||||||||
| 37 | |||||||||||
| 38 | =item * L<EntityModel::Web::Page> - page definition, specfiying the handlers, templates, data and URL(s) for a specific | ||||||||||
| 39 | page. | ||||||||||
| 40 | |||||||||||
| 41 | =item * L<EntityModel::Web::Context> - active request handler, includes everything appropriate for a single HTTP request. | ||||||||||
| 42 | |||||||||||
| 43 | =item * L<EntityModel::Web::Authorization> - support for authorization on a single request. | ||||||||||
| 44 | |||||||||||
| 45 | =item * L<EntityModel::Web::Authentication> - support for request authentication. | ||||||||||
| 46 | |||||||||||
| 47 | =item * L<EntityModel::Web::Session> - store and retrieve data between requests for a user session | ||||||||||
| 48 | |||||||||||
| 49 | =back | ||||||||||
| 50 | |||||||||||
| 51 | Definitions are stored under the C<web> key as a list of sites: | ||||||||||
| 52 | |||||||||||
| 53 | web: [ | ||||||||||
| 54 | host: something.com | ||||||||||
| 55 | page: [ | ||||||||||
| 56 | name: 'Index' | ||||||||||
| 57 | path: '' | ||||||||||
| 58 | pathtype: string | ||||||||||
| 59 | title: 'Index page' | ||||||||||
| 60 | ] | ||||||||||
| 61 | ] | ||||||||||
| 62 | |||||||||||
| 63 | =cut | ||||||||||
| 64 | |||||||||||
| 65 | 5 | ▶ | use URI; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 66 | 5 | ▶ | use EntityModel::Web::Site; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 67 | 5 | ▶ | use EntityModel::Web::Context; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 68 | 5 | ▶ | use EntityModel::Template; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 69 | |||||||||||
| 70 | =head1 METHODS | ||||||||||
| 71 | |||||||||||
| 72 | =cut | ||||||||||
| 73 | |||||||||||
| 74 | =head2 register | ||||||||||
| 75 | |||||||||||
| 76 | Registers this module as a plugin with the L<EntityModel> main classes. | ||||||||||
| 77 | |||||||||||
| 78 | =cut | ||||||||||
| 79 | |||||||||||
| 80 | 3 | ▶ | sub register { | ||||||||
|
Subroutine
register: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 81 | 3 | my $self = shift; | |||||||||
| 82 | 3 | my $model = shift; | |||||||||
| 83 | $model->provide_handler_for( | ||||||||||
| 84 | 3 | ▶ | web => $self->sap(sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 85 | 3 | my ($self, $model, %args) = @_; | |||||||||
| 86 | 3 | $self->site->push(EntityModel::Web::Site->new($_)) for @{$args{data}}; | |||||||||
| 87 | }) | ||||||||||
| 88 | 3 | ); | |||||||||
| 89 | 3 | return $self; | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | =head2 page_from_uri | ||||||||||
| 93 | |||||||||||
| 94 | =cut | ||||||||||
| 95 | |||||||||||
| 96 | 4 | ▶ | sub page_from_uri { | ||||||||
|
Subroutine
page_from_uri: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 97 | 4 | my $self = shift; | |||||||||
| 98 | 4 | my $uri = shift; | |||||||||
| 99 | 4 | my ($site) = grep { $_->host eq $uri->host } $self->site->list; | |||||||||
| 100 | 4 | ▶ | return EntityModel::Error->new($self, "No site") unless $site; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | |||||||||||
| 102 | 4 | my $page = $site->page_from_uri($uri); | |||||||||
| 103 | 4 | ▶ | return EntityModel::Error->new($self, "No page") unless $page; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 104 | 3 | return $page; | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | 5 | 1; | |||||||||
| 108 | |||||||||||
| 109 | __END__ | ||||||||||