| 1 | package Froody::Response::Content; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 36 | ▶ | use base qw(Froody::Response); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 36 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 36 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 36 | our $VERSION = "0.01"; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 36 | ▶ | use Storable; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 36 | ▶ | use Froody::Error; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | Froody::Response::Content - common subclass for perl data structure classes | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | package Froody::Response::Subclass; | ||||||||||||||||||||||||||||||||||||||||||
| 19 | use base qw(Froody::Response::Content); | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | This is a common subclass used by PerlDS and Terse. Unless you're | ||||||||||||||||||||||||||||||||||||||||||
| 24 | considering patching this file, I wouldn't look at it if I were you. | ||||||||||||||||||||||||||||||||||||||||||
| 25 | All these methods are documented again properly in those classes documentation. | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | Note, there's a C<_to_xml> method that isn't implemented here and has | ||||||||||||||||||||||||||||||||||||||||||
| 28 | to be implemented by our subclasses | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | =head2 Methods | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | =item status | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | Get/set the status. you can only set this to be "ok" or "fail" or it'll | ||||||||||||||||||||||||||||||||||||||||||
| 37 | throw a Froody::Error of "perl.methodcall.param" | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 183 | ▶ | sub status { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status: called CC=5 SCAR=17.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 183 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 183 | ▶ | return $self->{status} unless @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 51 | ▶ | unless ($_[0] && ($_[0] eq "ok" || $_[0] eq "fail")) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$_[0] and $_[0] eq "ok" || $_[0] eq "fail"
$_[0] eq "ok" or $_[0] eq "fail"
MC/DC0%0/3
$_[0] and $_[0] eq "ok" || $_[0] eq "fail"
$_[0]
$_[0] eq "ok"
$_[0] eq "fail"
Truth table50%2/4
A and B or C
A= $_[0]B= $_[0] eq "ok"C= $_[0] eq "fail"
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | { Froody::Error->throw("perl.methodcall.param", "status can only be set to 'ok' or 'fail'") } | |||||||||||||||||||||||||||||||||||||||||
| 46 | 51 | $self->{status} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 51 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | =item content | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | Get/set the content. When you set the content it is cloned, but the | ||||||||||||||||||||||||||||||||||||||||||
| 53 | actual data structure is returned when you get - so you can alter it directly. | ||||||||||||||||||||||||||||||||||||||||||
| 54 | This is considered a feature. | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 244 | ▶ | sub content { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
content: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 244 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 244 | ▶ | return $self->{content} unless @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | # did we get a hash? | ||||||||||||||||||||||||||||||||||||||||||
| 63 | # unless(ref $_[0] && ref $_[0] eq "HASH") | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # { Froody::Error/::Params->throw("content may only be set to a hashref"); } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | # default values | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 92 | ▶ | $self->status('ok') unless $self->status; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 92 | ▶ | $self->{content} = ref ($_[0]) ? Storable::dclone shift : shift; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 92 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 71 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 8 | ▶ | sub render { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=3 SCAR=12.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 8 | my %args = $self->validate_object(@_, {}); | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | ## check for errors | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | # no content? | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 8 | ▶ | unless ($self->content) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | # we can allow empty responses. | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $self->content({}); | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | # bad status? | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 8 | ▶ | unless ($self->status) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | Froody::Error->throw("froody.response", | |||||||||||||||||||||||||||||||||||||||||
| 88 | "Status must be set to 'ok' or 'fail', not undefined" | ||||||||||||||||||||||||||||||||||||||||||
| 89 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | # call the actual render method | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 8 | $self->raw_render(); | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | =item raw_render | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | A routine used by the renderer. No user servicable parts | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | sub raw_render() | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
raw_render: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | # get a XML::LibXML::Document representing this document | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 8 | my $doc = $self->_to_xml($self->content); | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | # get the XML string, and encode to UTF8 octets | ||||||||||||||||||||||||||||||||||||||||||
| 111 | # pass in 1 here to get nice whitespace | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 7 | my $content = $doc->toString(1); | |||||||||||||||||||||||||||||||||||||||||
| 113 | 7 | return Encode::encode("utf-8", $content); | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | =item as_xml | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | We proxy to the _to_xml method rather than replying on bytification and | ||||||||||||||||||||||||||||||||||||||||||
| 119 | back again. | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | # shortcut. We don't have to go all the way to a string | ||||||||||||||||||||||||||||||||||||||||||
| 124 | # and back up again to turn this into XML, we can go directly | ||||||||||||||||||||||||||||||||||||||||||
| 125 | sub as_xml | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_xml: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 6 | my $xml = Froody::Response::XML->new(); | |||||||||||||||||||||||||||||||||||||||||
| 129 | 6 | $xml->structure($self->structure); | |||||||||||||||||||||||||||||||||||||||||
| 130 | 6 | $xml->xml($self->_to_xml($self->content)); | |||||||||||||||||||||||||||||||||||||||||
| 131 | 6 | return $xml; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | None known. | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | Please report any bugs you find via the CPAN RT system. | ||||||||||||||||||||||||||||||||||||||||||
| 141 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Froody> | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | Copyright Fotango 2005. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | Please see the main L<Froody> documentation for details of who has worked | ||||||||||||||||||||||||||||||||||||||||||
| 148 | on this project. | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | This module is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 151 | the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | L<Froody>, L<Froody::Response>, L<Froody::Response::Terse>, | ||||||||||||||||||||||||||||||||||||||||||
| 156 | L<Froody::Response::PerlDS> | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 36 | 1; | |||||||||||||||||||||||||||||||||||||||||