blib/lib/Froody/Response/String.pm

filter: Statementstmt 81.4% 22 / 27 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 7 / 9 Podpod 60.0% 3 / 5 totaltotal 78.0% 32 / 41 CC 1 SCAR 2.0
CC
1
Cov
81%
as_string
2.0
as_string
2.0
BEGIN
1.0
CRAP 1.2
« blib/lib/Froody/Renderer/json.pm ↑ Summary blib/lib/Froody/ErrorType.pm »
1 package Froody::Response::String;
2 30 ▶use base qw(Froody::Response);
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 30 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Froody::Response::String - create a response from a string
12  
13 =head1 SYNOPSIS
14  
15 my $response = Froody::Response::String->new()
16 ->structure($froody_method)
17 ->set_string($string)
18 print $response->render;
19  
20 =head1 DESCRIPTION
21  
22 This is a concrete implementation of Froody::Response. It takes its input
23 from a valid Perl string, which you can set with C<set_string>:
24  
25 my $frs = Froody::Response::String->new();
26 $frs->structure($froody_method);
27 $frs->set_string( <<ENDOFRSP );
28 <rsp stat="ok">
29 <monger>L\x{e9}on Brocard</monger>
30 </rsp>
31 ENDOFRSP
32  
33 Note that there's no XML declaration header there - one will be added
34 automatically. You can also set the bytes directly:
35  
36 my $frs = Froody::Response::String->new();
37 $frs->structure($froody_method);
38 $frs->set_bytes( <<ENDOFRSP );
39 <?xml version="1.0" encoding="utf-8" ?>
40 <rsp stat="ok">
41 <monger>L\x{c3}\x{a9}on Brocard</monger>
42 </rsp>
43 ENDOFRSP
44  
45 In this case you are required to include the XML declaration header (as we
46 can't create one for you as we have no idea what encoding scheme the bytes are
47 using)
48  
49 =cut
50  
51 # set_string is documented
52 152 ▶sub set_string {
Subroutine set_string: called CC=1 SCAR=0.0
Pod undocumented
53 152 my $self = shift;
54 152 $self->{bytes} = qq{<?xml version="1.0" encoding="utf-8" ?>\n};
55 152 $self->{bytes} .= Encode::encode("utf-8", shift());
56 152 return $self;
57 }
58  
59 # set_bytes is documented
60 40 ▶sub set_bytes {
Subroutine set_bytes: called CC=1 SCAR=0.0
Pod undocumented
61 40 my $self = shift;
62 40 $self->{bytes} = shift;
63 40 return $self;
64 }
65  
66 # just return the bytes
67 24 ▶sub render { my $self = shift; $self->{bytes} }
Subroutine render: called CC=1 SCAR=0.0
Pod documented
68  
69 =head2 Converting other Responses to Froody::Response::String objects
70  
71 Once you've loaded this class you can automatically convert other
72 Froody::Response class instances to Froody::Response::String objects with
73 the C<as_string> method.
74  
75 use Froody::Response::String;
76 my $string = Froody::Response::Terse
77 ->new()
78 ->structure($froody_method)
79 ->content(...)
80 ->as_string;
81 print ref($string); # prints "Froody::Response::String"
82  
83 =cut
84  
85 # rendering this class
86 # as_string is documented
87 0 ▶sub as_string { return $_[0] }
Subroutine as_string: not called CC=1 SCAR=6.9
Pod documented
88 sub Froody::Response::as_string
89 0 ▶{
Subroutine as_string: not called CC=1 SCAR=6.9
Pod documented
90 0 my $self = shift;
91 0 my $str = Froody::Response::String->new();
92 0 $str->set_bytes($self->render);
93 0 return $str;
94 }
95  
96 =head1 BUGS
97  
98 None known.
99  
100 Please report any bugs you find via the CPAN RT system.
101 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Froody>
102  
103 =head1 AUTHOR
104  
105 Copyright Fotango 2005. All rights reserved.
106  
107 Please see the main L<Froody> documentation for details of who has worked
108 on this project.
109  
110 This module is free software; you can redistribute it and/or modify it under
111 the same terms as Perl itself.
112  
113 =head1 SEE ALSO
114  
115 L<Froody>, L<Froody::Response>
116  
117 =cut
118  
119 30 1;
« blib/lib/Froody/Renderer/json.pm ↑ Summary blib/lib/Froody/ErrorType.pm »