App/LiquidTidy.pm

filter: Statementstmt 95.0% 38 / 40 Branchbran 50.0% 4 / 8 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 80.8% 55 / 68 CC 7 SCAR 15.4
CC
7
Cov
81%
run
8.8
BEGIN
1.0
BEGIN
1.0
CRAP 4.6
« Template/LiquidX/Tidy.pm ↑ Summary Template/LiquidX/Tidy/Liquid/Utility.pm »
1 package App::LiquidTidy;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '0.03';
8  
9 1 ▶use Template::LiquidX::Tidy;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Template::Liquid;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Template::LiquidX::Tidy::Tag::include;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Template::LiquidX::Tidy::Tag::post_url;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶sub new ($class, $args) {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
15 1 bless $args => $class
16 }
17  
18 1 ▶sub run ($self) {
Subroutine run: called CC=7 SCAR=21.8
Pod documented
19 1 ▶ die "No file name specified\n" unless $self->{file};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"file"} 0 1 1
20 1 my $fh;
21 1 ▶ if ($self->{file} eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'file'} eq '-') { } 0 1 1
22 0 $fh = *STDIN;
23 }
24 else {
25 1 ▶ open $fh, '<', $self->{file} or die "Error opening $self->{file}: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $self->{"file"} or die qq[Error opening $self->{"file"}: $!\n] 1 0 1
26 }
27 1 my $content = do { local $/; <$fh>; };
28  
29 1 my $sol = Template::Liquid->parse($content);
30  
31 1 my $liquid_tidy;
32 1 my %opts = (
33 force_nl => 1,
34 );
35 1 ▶ if ($self->{file} =~ /\.markdown/ || $self->{file} =~ /\.md/ || $self->{file} =~ /\.txt/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"file"} =~ /\.markdown/ or $self->{"file"} =~ /\.md/ or $self->{"file"} =~ /\.txt/) 0 1 1
Condition33%2/6
$self->{"file"} =~ /\.markdown/ or $self->{"file"} =~ /\.md/ or $self->{"file"} =~ /\.txt/
l!l&&r!l&&!r
001
$self->{"file"} =~ /\.markdown/ or $self->{"file"} =~ /\.md/
l!l&&r!l&&!r
001
MC/DC0%0/3
$self->{"file"} =~ /\.markdown/ or $self->{"file"} =~ /\.md/ or $self->{"file"} =~ /\.txt/
$self->{"file"} =~ /\.markdown/ $self->{"file"} =~ /\.md/ $self->{"file"} =~ /\.txt/
Truth table25%1/4
A or B or C
A= $self->{"file"} =~ /\.markdown/B= $self->{"file"} =~ /\.md/C= $self->{"file"} =~ /\.txt/
ABCresult
1XX1
01X1
0011
0000
36 0 $opts{html} = 0;
37 }
38  
39 1 %opts = (%opts, %$self);
40 1 $liquid_tidy = $sol->{document}->tidy(\%opts);
41 1 print $liquid_tidy;
42 }
43  
44 # print Dumper $sol->{document};
45 # print $sol->{document}->dump();
46 # print $sol->{document}->tidy({force_nl => 1});
47 # my $liquid_tidy = $sol->{document}->tidy();
48  
49 # sub test_html_tidy ($source) {
50 # my ($trans, $map) = Template::Liquid->parse($sol)->{document}->transform();
51 # print $trans;
52 # my @cmd = (qw(tidy
53 # --indent auto
54 # --indent-spaces 4
55 # --show-body-only auto
56 # --fix-uri no
57 # --literal-attributes yes
58 # --preserve-entities yes
59 # --new-pre-tags body
60 # --quiet
61 # ));
62 # my ($out, $err);
63 # IPC::Run::run \@cmd, \$trans, \$out, \$err; warn "tidy: $?";
64  
65 # print transform_back($out, $map);
66 # }
67  
68 # sub dump_map ($map) {
69 # for (sort { $a <=> $b } grep !/^__/, keys $map->%*) {
70 # my $i = $map->{$_};
71 # print $_, "\t", (defined $i->{markup} ? $i->{markup} =~ s/\n\K/\t/gr : ''), "\n";
72 # print "\t", $i->{markup_2} =~ s/\n\K/\t/gr, "\n"
73 # if defined $i->{markup_2};
74 # print "\n";
75 # }
76 # }
77  
78 1 1;
79  
80 =head1 NAME
81  
82 App::LiquidTidy - Implementation for liquid_tidy script
83  
84 =head1 SYNOPSIS
85  
86 use App::LiquidTidy;
87 my $app = App::LiquidTidy->new(%options);
88 $app->run;
89  
90 =head1 DESCRIPTION
91  
92 See L<liquid_tidy> for the command line tool documentation.
93  
94 =head1 METHODS
95  
96 =head2 new(%options)
97  
98 Create a new app.
99  
100 It will parse the file specified by C<$options{file}>
101  
102 Other C<%options> are passed to Template::LiquidX::Tidy
103  
104 =head2 run
105  
106 Print the formatted file to standard output.
107  
108 =cut
109  
« Template/LiquidX/Tidy.pm ↑ Summary Template/LiquidX/Tidy/Liquid/Utility.pm »