ZofCMS/Plugin/Syntax/Highlight/HTML.pm

filter: Statementstmt 34.2% 12 / 35 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 3 / 6 Podpod 0.0% 0 / 2 totaltotal 24.5% 15 / 61 CC 10 SCAR 40.1
CC
10
Cov
23%
process
90.0
_load_code_from_file
6.0
new
2.0
CRAP 55.1
« ZofCMS/Plugin/Syntax/Highlight/CSS.pm ↑ Summary ZofCMS/Plugin/NavMaker.pm »
1 package App::ZofCMS::Plugin::Syntax::Highlight::HTML;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '1.001010'; # VERSION
7  
8 1 require File::Spec;
9 1 ▶use Syntax::Highlight::HTML;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 0 ▶sub new { return bless {}, shift }
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
12  
13 0 ▶sub process {
Subroutine process: not called CC=9 SCAR=45.0
Pod undocumented
14 0 my ( $self, $template, $query, $config ) = @_;
15  
16 return
17 0 ▶ unless $template->{highlight_html};
Branch: 1 branch
BranchTrueFalseTotal
unless $template->{"highlight_html"} 0 0 0
18  
19 0 my %highlights = %{ delete $template->{highlight_html} };
20  
21 my $code_before = exists $template->{highlight_before}
22 ? delete $template->{highlight_before}
23 0 ▶ : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $template->{'highlight_before'} ? : 0 0 0
24  
25 my $code_after = exists $template->{highlight_after}
26 ? delete $template->{highlight_after}
27 0 ▶ : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $template->{'highlight_after'} ? : 0 0 0
28  
29 my $highlighter = Syntax::Highlight::HTML->new(
30 nnn => ( defined $highlights{nnn} ? $highlights{nnn} : 0 ),
31 0 ▶ pre => ( defined $highlights{pre} ? $highlights{pre} : 1 ),
Branch: 2 branches
BranchTrueFalseTotal
defined $highlights{'nnn'} ? : 0 0 0
defined $highlights{'pre'} ? : 0 0 0
32 );
33  
34 0 keys %highlights;
35 0 ▶ while ( my ( $tag, $code ) = each %highlights ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %highlights) 0 0 0
36 0 ▶ if ( ref $code eq 'SCALAR' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $code eq 'SCALAR') { } 0 0 0
elsif (ref $code eq 'CODE') { } 0 0 0
37 $code = $self->_load_code_from_file(
38 $config->conf->{data_store},
39 0 $$code,
40 );
41 }
42 elsif ( ref $code eq 'CODE' ) {
43 0 $code = $code->($template, $query, $config);
44 }
45  
46 0 $template->{t}{$tag}
47 = $code_before . $highlighter->parse( $code ) . $code_after;
48 }
49  
50 0 return 1;
51 }
52  
53 0 ▶sub _load_code_from_file {
Subroutine _load_code_from_file: not called CC=2 SCAR=17.9
54 0 my ( $self, $data_dir, $filename ) = @_;
55 0 my $code_file = File::Spec->catfile( $data_dir, $filename );
56  
57 0 ▶ open my $fh, '<', $code_file
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $code_file or return "Failed to open $code_file [$!]" 0 0 0
58 or return "Failed to open $code_file [$!]";
59  
60 0 my $code = do { local $/; <$fh>; };
61 0 close $fh;
62  
63 0 return $code;
64 }
65  
66 1 1;
67 __END__
« ZofCMS/Plugin/Syntax/Highlight/CSS.pm ↑ Summary ZofCMS/Plugin/NavMaker.pm »