blib/lib/Catalyst/Plugin/AtomPP.pm

filter: Statementstmt 29.1% 14 / 48 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 23.4% 19 / 81 CC 12 SCAR 47.6
CC
12
Cov
20%
atom
156.0
BEGIN
1.0
BEGIN
1.0
CRAP 117.2
↑ Summary
1 package Catalyst::Plugin::AtomPP;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Catalyst::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use XML::Atom;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use XML::Atom::Entry;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 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 0 ▶sub atom {
Subroutine atom: not called CC=12 SCAR=50.5
Pod documented
59 0 my $c = shift;
60  
61 0 my $class = caller(0);
62 0 (my $method = $c->req->action) =~ s!.*/!!;
63  
64 0 my %prefixes = (
65 POST => 'create_',
66 GET => 'retrieve_',
67 PUT => 'update_',
68 DELETE => 'delete_',
69 );
70  
71 0 ▶ if (my $prefix = $prefixes{$c->req->method}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $prefix = $prefixes{$c->req->method}) { } 0 0 0
72 0 $method = $prefix.$method;
73 } else {
74 0 $c->log->debug(qq!Unsupported Method "@{[$c->req->method]}" called!);
75 0 $c->res->status(501);
76 0 return;
77 }
78  
79 0 $c->log->debug("Method: $method");
80  
81 0 ▶ if (my $code = $class->can($method)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $class->can($method)) 0 0 0
82 0 my ($pp, $res);
83  
84 0 for my $attr (@{Catalyst::Utils::attrs($code)}) {
85 0 ▶ $pp++ if $attr eq 'Remote';
Branch: 1 branch
BranchTrueFalseTotal
if $attr eq "Remote" 0 0 0
86 }
87  
88 0 ▶ if ($pp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pp) { } 0 0 0
89 0 my $content = $c->req->body;
90 0 my $entry;
91 0 ▶ $entry = XML::Atom::Entry->new(\$content) if $content;
Branch: 1 branch
BranchTrueFalseTotal
if $content 0 0 0
92 0 ▶ if ($c->req->body and !$entry) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->req->body and not $entry) { } 0 0 0
Condition0%0/3
$c->req->body and not $entry
!ll&&!rl&&r
000
MC/DC0%0/2
$c->req->body and not $entry
$c->req->body not $entry
Truth table0%0/3
A and not(B)
A= $c->req->bodyB= not $entry
ABresult
0X0
100
111
93 0 $c->log->debug("Request body is not well-formed.");
94 0 $c->res->status(415);
95 } else {
96 0 ▶ $class = $c->components->{$class} || $class;
Condition0%0/3
$c->components->{$class} || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
$c->components->{$class} || $class
$c->components->{$class} $class
Truth table0%0/3
A || B
A= $c->components->{$class}B= $class
ABresult
1X1
011
000
97 0 my @args = @{$c->req->args};
98 0 ▶ $c->req->args([$entry]) if $entry;
Branch: 1 branch
BranchTrueFalseTotal
if $entry 0 0 0
99 0 ▶ $c->actions->{reverse}->{$code} ||= "$class->$method";
Condition0%0/2
$c->actions->{"reverse"}{$code} ||= "$class->$method"
l!l
00
MC/DC0%0/1
$c->actions->{"reverse"}{$code} ||= "$class->$method"
$c->actions->{"reverse"}{$code}
Truth table0%0/2
A
A= $c->actions->{"reverse"}{$code}
Aresult
11
00
100 0 $c->state($c->execute($class, $code));
101  
102 0 $c->res->content_type('application/xml; charset=utf-8');
103 0 $c->res->body($c->state);
104 0 $c->req->args(\@args);
105 }
106 }
107  
108 else {
109 0 $c->log->debug(qq!Method "$method" has no Atom attribute!);
110 0 $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 1;
133  
↑ Summary