| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package EntityModel::Web::Page; |
|
2
|
|
|
|
|
|
|
{ |
|
3
|
|
|
|
|
|
|
$EntityModel::Web::Page::VERSION = '0.004'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
use EntityModel::Class { |
|
6
|
1
|
|
|
|
|
22
|
name => 'string', |
|
7
|
|
|
|
|
|
|
path => 'string', |
|
8
|
|
|
|
|
|
|
pathtype => 'string', |
|
9
|
|
|
|
|
|
|
title => 'string', |
|
10
|
|
|
|
|
|
|
description => 'string', |
|
11
|
|
|
|
|
|
|
template => 'string', |
|
12
|
|
|
|
|
|
|
separator => { type => 'string', default => '/' }, |
|
13
|
|
|
|
|
|
|
parent => { type => 'EntityModel::Web::Page' }, |
|
14
|
|
|
|
|
|
|
pathinfo => { type => 'array', subclass => 'EntityModel::Web::Page::Pathinfo' }, |
|
15
|
|
|
|
|
|
|
data => { type => 'array', subclass => 'EntityModel::Web::Page::Data' }, |
|
16
|
|
|
|
|
|
|
content => { type => 'array', subclass => 'EntityModel::Web::Page::Content' }, |
|
17
|
|
|
|
|
|
|
content_by_section => { type => 'hash', subclass => 'EntityModel::Web::Page::Content', watch => { content => 'section' } }, |
|
18
|
|
|
|
|
|
|
handler => { type => 'array', subclass => 'EntityModel::Web::Page::Handler' }, |
|
19
|
|
|
|
|
|
|
handler_for_http_verb => { type => 'hash', subclass => 'EntityModel::Web::Page::Handler', watch => { handler => 'type' } }, |
|
20
|
1
|
|
|
1
|
|
688
|
}; |
|
|
1
|
|
|
|
|
2
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
EntityModel::Web::Page - handle page definitions |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 VERSION |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
version 0.004 |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
|
35
|
|
|
|
|
|
|
|
|
36
|
1
|
|
|
1
|
|
1329
|
use EntityModel::Web::Response; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
6
|
|
|
37
|
1
|
|
|
1
|
|
56
|
use Data::Dumper; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
1082
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 METHODS |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub new { |
|
44
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
45
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new; |
|
46
|
0
|
|
|
|
|
|
my %args = @_; |
|
47
|
0
|
|
|
|
|
|
my $site = delete $args{site}; |
|
48
|
0
|
|
|
|
|
|
$self->separator('/'); |
|
49
|
0
|
|
|
|
|
|
foreach my $item (qw(name path pathtype title description separator template)) { |
|
50
|
0
|
0
|
|
|
|
|
if(defined(my $v = delete $args{$item})) { |
|
51
|
0
|
|
|
|
|
|
$self->$item($v); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
} |
|
54
|
0
|
0
|
|
|
|
|
$self->pathtype('string') unless $self->pathtype; |
|
55
|
0
|
0
|
|
|
|
|
if(my $pathinfo = delete $args{pathinfo}) { |
|
56
|
0
|
|
|
|
|
|
$self->pathinfo->push(EntityModel::Web::Page::Pathinfo->new($_)) for @$pathinfo; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
0
|
0
|
|
|
|
|
if(my $data = delete $args{data}) { |
|
59
|
0
|
|
|
|
|
|
$self->data->push(EntityModel::Web::Page::Data->new($_)) for @$data; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
0
|
0
|
|
|
|
|
if(my $content = delete $args{content}) { |
|
62
|
0
|
|
|
|
|
|
$self->content->push(EntityModel::Web::Page::Content->new(%$_)) for @$content; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
0
|
0
|
|
|
|
|
if(my $handler = delete $args{handler}) { |
|
65
|
0
|
|
|
|
|
|
$self->handler->push(EntityModel::Web::Page::Handler->new($_)) for @$handler; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
0
|
0
|
|
|
|
|
if(my $parent = delete $args{parent}) { |
|
68
|
0
|
|
|
|
|
|
$self->parent($site->page_by_name->get($parent)); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
# warn "Create page with " . Dumper \%args; |
|
71
|
|
|
|
|
|
|
# warn "Page " . $self->name; |
|
72
|
|
|
|
|
|
|
# warn " * Description " . ($self->description // ''); |
|
73
|
|
|
|
|
|
|
# warn " * Path " . ($self->path // ''); |
|
74
|
|
|
|
|
|
|
# warn " * Pathtype " . ($self->pathtype // ''); |
|
75
|
|
|
|
|
|
|
# warn " * Title " . ($self->title // ''); |
|
76
|
0
|
0
|
|
|
|
|
die "pathtype not defined" unless defined $self->pathtype; |
|
77
|
0
|
|
|
|
|
|
return $self; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub handle_request { |
|
81
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
82
|
0
|
|
|
|
|
|
my %args = @_; |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
my $req = delete $args{request} or die "No request supplied"; |
|
85
|
0
|
|
|
|
|
|
my $response = EntityModel::Web::Response->new( |
|
86
|
|
|
|
|
|
|
request => $req, |
|
87
|
|
|
|
|
|
|
page => $self |
|
88
|
|
|
|
|
|
|
); |
|
89
|
|
|
|
|
|
|
# $response->apply_data(delete $args{data}) if exists $args{data}; |
|
90
|
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
logDebug("Looking for handler on [%s] for %s", $req->method, $self->name); |
|
92
|
0
|
|
|
|
|
|
logDebug("-> [%s]", $_) for keys %{ $self->handler_for_http_verb }; |
|
|
0
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# If we have a handler set up for this request, use it |
|
94
|
0
|
0
|
|
|
|
|
if(my $handler = $self->handler_for_http_verb->get($req->method)) { |
|
95
|
0
|
|
|
|
|
|
logWarning("Found [%s]", $handler); |
|
96
|
0
|
|
|
|
|
|
my $rslt = $handler->($response); |
|
97
|
|
|
|
|
|
|
# And pass the value back if true (which means the handler's done everything we need) |
|
98
|
0
|
0
|
|
|
|
|
return $rslt if $rslt; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
return $response; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub extract_data { |
|
105
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
106
|
0
|
|
|
|
|
|
my $data = shift; |
|
107
|
0
|
|
|
|
|
|
my %pathinfo; |
|
108
|
0
|
|
|
|
|
|
foreach my $pi ($self->pathinfo->list) { |
|
109
|
0
|
|
|
|
|
|
$pathinfo{$pi->name} = shift @$data; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
0
|
|
|
|
|
|
return %pathinfo; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
__END__ |