| 1 | package App::ZofCMS::Plugin::Syntax::Highlight::CSS; | ||||||||||||||
| 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::CSS; | ||||||||||||
|
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_css}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 18 | |||||||||||||||
| 19 | 0 | my %highlights = %{ delete $template->{highlight_css} }; | |||||||||||||
| 20 | |||||||||||||||
| 21 | my $code_before = exists $template->{highlight_css_before} | ||||||||||||||
| 22 | ? delete $template->{highlight_css_before} | ||||||||||||||
| 23 | 0 | ▶ | : ''; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 24 | |||||||||||||||
| 25 | my $code_after = exists $template->{highlight_css_after} | ||||||||||||||
| 26 | ? delete $template->{highlight_css_after} | ||||||||||||||
| 27 | 0 | ▶ | : ''; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 28 | |||||||||||||||
| 29 | my $highlighter = Syntax::Highlight::CSS->new( | ||||||||||||||
| 30 | nnn => ( defined $highlights{nnn} ? $highlights{nnn} : 0 ), | ||||||||||||||
| 31 | 0 | ▶ | pre => ( defined $highlights{pre} ? $highlights{pre} : 1 ), | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 32 | ); | ||||||||||||||
| 33 | |||||||||||||||
| 34 | 0 | keys %highlights; | |||||||||||||
| 35 | 0 | ▶ | while ( my ( $tag, $code ) = each %highlights ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 36 | 0 | ▶ | if ( ref $code eq 'SCALAR' ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 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
| |||||||||||||||
| 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__ | ||||||||||||||