line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::AtomPP; |
2
|
1
|
|
|
1
|
|
26743
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
3
|
1
|
|
|
1
|
|
571
|
use Catalyst::Utils; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use XML::Atom; |
5
|
|
|
|
|
|
|
use XML::Atom::Entry; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Catalyst::Plugin::AtomPP - Dispatch AtomPP methods with Catalyst. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Catalyst qw/AtomPP/; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub entry : Local { |
18
|
|
|
|
|
|
|
my ($self, $c) = @_; |
19
|
|
|
|
|
|
|
$c->atom; # dispatch AtomPP methods. |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub create_entry : Remote { |
23
|
|
|
|
|
|
|
my ($self, $c, $entry) = @_; |
24
|
|
|
|
|
|
|
# $entry is XML::Atom Object from Request content |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
... |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub retrieve_entry : Remote { |
30
|
|
|
|
|
|
|
my ($self, $c) = @_; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
... |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub update_entry : Remote { |
36
|
|
|
|
|
|
|
... |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub delete_entry : Remote { |
40
|
|
|
|
|
|
|
... |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 DESCRIPTION |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
This plugin allows you to dispatch AtomPP methods with Catalyst. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Require other authentication plugin, if needed. |
48
|
|
|
|
|
|
|
(Authentication::CDBI::Basic, WSSE, or so) |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 METHODS |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=over 4 |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item atom |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub atom { |
59
|
|
|
|
|
|
|
my $c = shift; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $class = caller(0); |
62
|
|
|
|
|
|
|
(my $method = $c->req->action) =~ s!.*/!!; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my %prefixes = ( |
65
|
|
|
|
|
|
|
POST => 'create_', |
66
|
|
|
|
|
|
|
GET => 'retrieve_', |
67
|
|
|
|
|
|
|
PUT => 'update_', |
68
|
|
|
|
|
|
|
DELETE => 'delete_', |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
if (my $prefix = $prefixes{$c->req->method}) { |
72
|
|
|
|
|
|
|
$method = $prefix.$method; |
73
|
|
|
|
|
|
|
} else { |
74
|
|
|
|
|
|
|
$c->log->debug(qq!Unsupported Method "@{[$c->req->method]}" called!); |
75
|
|
|
|
|
|
|
$c->res->status(501); |
76
|
|
|
|
|
|
|
return; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$c->log->debug("Method: $method"); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
if (my $code = $class->can($method)) { |
82
|
|
|
|
|
|
|
my ($pp, $res); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
for my $attr (@{Catalyst::Utils::attrs($code)}) { |
85
|
|
|
|
|
|
|
$pp++ if $attr eq 'Remote'; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
if ($pp) { |
89
|
|
|
|
|
|
|
my $content = $c->req->body; |
90
|
|
|
|
|
|
|
my $entry; |
91
|
|
|
|
|
|
|
$entry = XML::Atom::Entry->new(\$content) if $content; |
92
|
|
|
|
|
|
|
if ($c->req->body and !$entry) { |
93
|
|
|
|
|
|
|
$c->log->debug("Request body is not well-formed."); |
94
|
|
|
|
|
|
|
$c->res->status(415); |
95
|
|
|
|
|
|
|
} else { |
96
|
|
|
|
|
|
|
$class = $c->components->{$class} || $class; |
97
|
|
|
|
|
|
|
my @args = @{$c->req->args}; |
98
|
|
|
|
|
|
|
$c->req->args([$entry]) if $entry; |
99
|
|
|
|
|
|
|
$c->actions->{reverse}->{$code} ||= "$class->$method"; |
100
|
|
|
|
|
|
|
$c->state($c->execute($class, $code)); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$c->res->content_type('application/xml; charset=utf-8'); |
103
|
|
|
|
|
|
|
$c->res->body($c->state); |
104
|
|
|
|
|
|
|
$c->req->args(\@args); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
else { |
109
|
|
|
|
|
|
|
$c->log->debug(qq!Method "$method" has no Atom attribute!); |
110
|
|
|
|
|
|
|
$c->res->status(501); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=back |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 SEE ALSO |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
L<Catalyst>, L<Catalyst::Plugin::XMLRPC>. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 AUTHOR |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Daisuke Murase, E<lt>typester@cpan.orgE<gt> |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 COPYRIGHT |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
This program is free software; you can redistribute |
128
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
133
|
|
|
|
|
|
|
|