GraphQL/UITemplate.pm

filter: Statementstmt 36.6% 11 / 30 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 25.0% 2 / 8 Podpod 0.0% 0 / 4 totaltotal 29.5% 13 / 44 CC 2 SCAR 9.8
CC
2
Cov
34%
safe_serialize
6.0
_build_tt
2.0
_build_template
2.0
CRAP 2.7
« GraphQL.pm ↑ Summary GraphQL/Exceptions.pm »
1 package Plack::App::GraphQL::UITemplate;
2  
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Plack::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 has tt => (
7 is => 'ro',
8 required => 1,
9 builder => '_build_tt',
10 handles => {
11 tt_process => 'process',
12 }
13 );
14  
15 0 ▶ sub _build_tt {
Subroutine _build_tt: not called CC=1 SCAR=6.9
16 0 return Plack::Util::load_class('Template::Tiny')->new();
17 }
18  
19 1 has template => (
20 is => 'ro',
21 required => 1,
22 builder => '_build_template',
23 );
24  
25 0 ▶ sub _build_template {
Subroutine _build_template: not called CC=1 SCAR=6.9
26 0 $/ = undef;
27 0 return my $data = <DATA>;
28 }
29  
30 1 has json_encoder => (
31 is => 'ro',
32 required => 1,
33 handles => {
34 json_encode => 'encode',
35 },
36 );
37  
38 1 has graphiql_version => (
39 is => 'ro',
40 required => 1,
41 default => 'latest',
42 );
43  
44 0 ▶sub safe_serialize {
Subroutine safe_serialize: not called CC=2 SCAR=17.9
Pod undocumented
45 0 my ($self, $data) = @_;
46 0 ▶ if($data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data) { } 0 0 0
47 0 my $json = $self->json_encode($data);
48 0 $json =~ s#/#\\/#g;
49 0 return $json;
50 } else {
51 0 return 'undefined';
52 }
53 }
54  
55 0 ▶sub process {
Subroutine process: not called CC=1 SCAR=6.9
Pod undocumented
56 0 my ($self, $req) = @_;
57 0 my $query = $req->query_parameters;
58 0 my %args = $self->args_from_query($query);
59 0 return my $body = $self->process_args(%args);
60 }
61  
62 0 ▶sub args_from_query {
Subroutine args_from_query: not called CC=1 SCAR=6.9
Pod undocumented
63 0 my ($self, $query) = @_;
64 return my %args = (
65 graphiql_version => $self->graphiql_version,
66 queryString => $self->safe_serialize( $query->{'query'} ),
67 operationName => $self->safe_serialize( $query->{'operationName'} ),
68 resultString => $self->safe_serialize( $query->{'result'} ),
69 0 variablesString => $self->safe_serialize( $query->{'variables'} ),
70 );
71 }
72  
73 0 ▶sub process_args {
Subroutine process_args: not called CC=1 SCAR=6.9
Pod undocumented
74 0 my ($self, %args) = @_;
75 0 my $input = $self->template;
76 0 $self->tt_process(\$input, \%args, \my $output);
77 0 return $output;
78 }
79  
80 1 1;
81  
82 =head1 NAME
83
84 Plack::App::GraphQL::UITemplate - Template and processing for the GraphQL UI
85  
86 =head1 SYNOPSIS
87
88 There's nothing really for end users here. Its just refactored into its own
89 package for code organization purposes.
90  
91 =head1 DESCRIPTION
92  
93 This is a package used to prepare and return an HTML response when you have the
94 'ui' flag enabled (probably for development) and the client requests an HTML
95 response. This is based on L<https://github.com/graphql/graphiql>
96  
97 Feel free to make your own improved development / query interface and put it on
98 CPAN!
99  
100 =head1 AUTHOR
101
102 John Napiorkowski
103  
104 =head1 SEE ALSO
105
106 L<Plack::App::GraphQL>
107
108 =cut
109  
110 __DATA__
« GraphQL.pm ↑ Summary GraphQL/Exceptions.pm »