File Coverage

blib/lib/TOML/Dumper/String.pm
Criterion Covered Total %
statement 20 20 100.0
branch 2 4 50.0
condition n/a
subroutine 4 4 100.0
pod 0 2 0.0
total 26 30 86.6


line stmt bran cond sub pod time code
1             package TOML::Dumper::String;
2 2     2   8 use strict;
  2         3  
  2         50  
3 2     2   9 use warnings;
  2         2  
  2         484  
4              
5             sub escape {
6 5     5 0 6 for (@_) {
7 5         6 s!\x5C!\\!xmgo; # backslash (U+005C)
8 5         3 s!\x08!\\b!xmgo; # backspace (U+0008)
9 5         6 s!\x09!\\t!xmgo; # tab (U+0009)
10 5         4 s!\x0A!\\n!xmgo; # linefeed (U+000A)
11 5         4 s!\x0C!\\f!xmgo; # form feed (U+000C)
12 5         3 s!\x0D!\\r!xmgo; # carriage return (U+000D)
13 5         3 s!\x22!\\"!xmgo; # quote (U+0022)
14 5         6 s!\x2F!\\/!xmgo; # slash (U+002F)
15             }
16 5 50       7 return wantarray ? @_ : $_[-1];
17             }
18              
19             sub quote {
20 5     5 0 4 my $value = shift;
21 5         5 $value = escape($value);
22 5 50       9 return qq{"""\n$value"""} if $value =~ s/\\n/\x0A/msg;
23 5         9 return qq{"$value"};
24             }
25              
26             1;
27             __END__