File Coverage

blib/lib/Data/Format/Pretty/YAML.pm
Criterion Covered Total %
statement 22 28 78.5
branch 2 4 50.0
condition 7 18 38.8
subroutine 4 5 80.0
pod 2 2 100.0
total 37 57 64.9


line stmt bran cond sub pod time code
1             package Data::Format::Pretty::YAML;
2              
3             our $DATE = '2014-12-10'; # DATE
4             our $VERSION = '0.08'; # VERSION
5              
6 1     1   665 use 5.010001;
  1         4  
  1         46  
7 1     1   7 use strict;
  1         2  
  1         284  
8 1     1   7 use warnings;
  1         2  
  1         375  
9              
10             require Exporter;
11             our @ISA = qw(Exporter);
12             our @EXPORT_OK = qw(format_pretty);
13              
14 0     0 1 0 sub content_type { "text/yaml" }
15              
16             sub format_pretty {
17 1     1 1 1783 my ($data, $opts) = @_;
18 1   50     7 $opts //= {};
19              
20 1         9 my $interactive = (-t STDOUT);
21 1   50     9 my $pretty = $opts->{pretty} // 1;
22 1   33     18 my $color = $opts->{color} // $ENV{COLOR} // $interactive //
      33        
      33        
23             $opts->{pretty};
24 1   33     11 my $linum = $opts->{linum} // $ENV{LINUM} // 0;
      50        
25              
26 1 50       5 if ($color) {
27 0         0 require YAML::Tiny::Color;
28 0         0 local $YAML::Tiny::Color::LineNumber = $linum;
29 0         0 YAML::Tiny::Color::Dump($data);
30             } else {
31 1         823 require YAML::Syck;
32 1         2534 local $YAML::Syck::ImplicitTyping = 1;
33 1         4 local $YAML::Syck::SortKeys = 1;
34 1         2 local $YAML::Syck::Headless = 1;
35 1 50       6 if ($linum) {
36 0         0 require String::LineNumber;
37 0         0 String::LineNumber::linenum(YAML::Syck::Dump($data));
38             } else {
39 1         7 YAML::Syck::Dump($data);
40             }
41             }
42             }
43              
44             1;
45             # ABSTRACT: Pretty-print data structure as YAML
46              
47             __END__