File Coverage

blib/lib/App/AutoCRUD/View/Yaml.pm
Criterion Covered Total %
statement 25 26 96.1
branch 1 2 50.0
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 33 36 91.6


line stmt bran cond sub pod time code
1             package App::AutoCRUD::View::Yaml;
2              
3 1     1   375 use 5.010;
  1         3  
4 1     1   4 use strict;
  1         1  
  1         20  
5 1     1   3 use warnings;
  1         1  
  1         22  
6              
7 1     1   3 use Moose;
  1         2  
  1         6  
8             extends 'App::AutoCRUD::View';
9              
10 1     1   4309 use YAML::Any;
  1         2  
  1         7  
11              
12 1     1   701 use namespace::clean -except => 'meta';
  1         2  
  1         8  
13              
14             has 'yaml_flags' => ( is => 'bare', isa => 'HashRef', default => sub {{}} );
15              
16              
17             sub render {
18 1     1 0 2 my ($self, $data, $context) = @_;
19              
20             # YAML modules don't have an OO API, so we must play with global variables
21 1         4 my $yaml_class = YAML::Any->implementation;
22 1         556 my $local_flags = "";
23 1         1 while (my ($flag, $val) = each %{$self->{yaml_flags}}) {
  1         5  
24 0         0 $local_flags .= "local \$${yaml_class}::$flag = q{$val};";
25             }
26 1 50       3 eval $local_flags if $local_flags;
27              
28 1         3 my $output = Dump $data;
29 1         21754 return [200, ['Content-type' => 'application/yaml'], [$output] ];
30             }
31              
32             1;
33              
34              
35             __END__
36              
37              
38