Writer/Render/PSGI.pm

filter: Statementstmt 48.6% 18 / 37 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 55.5% 5 / 9 Podpod 100% 4 / 4 totaltotal 50.0% 27 / 54 CC 3 SCAR 14.5
CC
3
Cov
44%
binary
12.0
new
2.0
redirect
2.0
CRAP 4.3
« PSGI.pm ↑ Summary Query/PSGI.pm »
1 package Labyrinth::Writer::Render::PSGI;
2  
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 our $VERSION = '1.01';
7  
8 =head1 NAME
9  
10 Labyrinth::Writer::Render::PSGI - Output Handler via PSGI for Labyrinth.
11  
12 =head1 SYNOPSIS
13  
14 use Labyrinth::Writer::Render::PSGI;
15 my $render = Labyrinth::Writer::Render::PSGI->new();
16  
17 $render->redirect($url); # HTTP redirect
18  
19 $render->publish($format, $text);
20  
21 =head1 DESCRIPTION
22  
23 Use CGI::PSGI to output text or redirect.
24  
25 =cut
26  
27 # -------------------------------------
28 # Library Modules
29  
30 4 ▶use CGI::PSGI;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 4 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 4 ▶use Labyrinth::Variables;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 # -------------------------------------
36 # Variables
37  
38 4 my $cgi = CGI::PSGI->new($settings{psgi}{env});
39  
40 # -------------------------------------
41 # The Subs
42  
43 =head1 METHODS
44  
45 =over 4
46  
47 =item new
48  
49 Object constructor.
50  
51 =item redirect($url)
52  
53 Redirect to given URL.
54  
55 =item binary($vars)
56  
57 Shorthand output of binary data and files.
58  
59 =item publish($format, $text)
60  
61 Publishes text output.
62  
63 =back
64  
65 =cut
66  
67 sub new {
68 0 ▶ my($class) = @_;
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
69  
70 0 my $self = bless { cgi => 1 }, $class;
71 0 $self;
72 }
73  
74 sub redirect {
75 0 ▶ my ($self, $url) = @_;
Subroutine redirect: not called CC=1 SCAR=6.9
Pod documented
76 0 ($settings{psgi}{status},$settings{psgi}{headers}) = $cgi->psgi_redirect($url);
77 }
78  
79 sub binary {
80 0 ▶ my ($self, $vars) = @_;
Subroutine binary: not called CC=3 SCAR=24.8
Pod documented
81  
82 0 my $fh = IO::File->new($settings{webdir}.'/'.$vars->{file},'r');
83 0 ▶ if($fh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh) 0 0 0
84 0 ($settings{psgi}{status},$settings{psgi}{headers}) = $cgi->psgi_header( -type => $vars->{ctype} );
85 0 my $buffer;
86 0 ▶ while(read($fh,$buffer,1024)) { $settings{psgi}{body} .= $buffer }
Branch: 1 branch
BranchTrueFalseTotal
if (read $fh, $buffer, 1024) 0 0 0
87 0 $fh->close;
88 }
89 }
90  
91 sub publish {
92 0 ▶ my ($self, $headers, $body) = @_;
Subroutine publish: not called CC=1 SCAR=6.9
Pod documented
93  
94 0 my %cgihash = map { '-' . $_ => $headers->{$_} } grep {$headers->{$_}} qw(type status cookie attachment);
95  
96 0 ($settings{psgi}{status},$settings{psgi}{headers}) = $cgi->psgi_header( %cgihash );
97 0 $settings{psgi}{body} .= $$body;
98 }
99  
100 4 1;
101  
102 __END__
103  
104 =head1 SEE ALSO
105  
106 CGI::PSGI,
107 Labyrinth
108  
109 =head1 AUTHOR
110  
111 Barbie, <barbie@missbarbell.co.uk> for
112 Miss Barbell Productions, L<http://www.missbarbell.co.uk/>
113  
114 =head1 COPYRIGHT & LICENSE
115  
116 Copyright (C) 2013-2014 Barbie for Miss Barbell Productions
117 All Rights Reserved.
118  
119 This module is free software; you can redistribute it and/or
120 modify it under the Artistic License 2.0.
121  
122 =cut
« PSGI.pm ↑ Summary Query/PSGI.pm »