| 1 | package Muster::LeafFile::txt; | ||||||||||||||||||||||||||||
| 2 | 1 | $Muster::LeafFile::txt::VERSION = '0.96'; | |||||||||||||||||||||||||||
| 3 | #ABSTRACT: Muster::LeafFile::txt - a plain text file in a Muster content tree | ||||||||||||||||||||||||||||
| 4 | =head1 NAME | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | Muster::LeafFile::txt - a plain text file in a Muster content tree | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 VERSION | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | version 0.96 | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | File nodes represent files in a Muster::Content content tree. | ||||||||||||||||||||||||||||
| 15 | This is a plain text file. | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Mojo::Base 'Muster::LeafFile'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use Mojo::Util 'decode'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use YAML::Any; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =head2 is_this_a_binary | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | Test if this type of file which just contains binary data. | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =cut | ||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub is_this_a_binary { | ||||||||||||||||||||||||||
|
Subroutine
is_this_a_binary: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | return undef; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =head2 build_html | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | Convert the content into HTML (output) format. | ||||||||||||||||||||||||||||
| 39 | If the output is going to be .txt, then leave it as it is. | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =cut | ||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub build_html { | ||||||||||||||||||||||||||
|
Subroutine
build_html: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | my $content = $self->cooked(); | |||||||||||||||||||||||||||
| 46 | # if the output is going to be text, don't process it | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if (defined $self->meta->{render_format} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->meta->{"render_format"} and $self->meta->{"render_format"} eq "txt"
MC/DC0%0/2
defined $self->meta->{"render_format"} and $self->meta->{"render_format"} eq "txt"
defined $self->meta->{"render_format"}
$self->meta->{"render_format"} eq "txt"
Truth table0%0/3
A and B
A= defined $self->meta->{"render_format"}B= $self->meta->{"render_format"} eq "txt"
| |||||||||||||||||||||||||||||
| 48 | and $self->meta->{render_format} eq 'txt') | ||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||
| 50 | 0 | return $content; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | 0 | return <<EOT; | |||||||||||||||||||||||||||
| 53 | <pre> | ||||||||||||||||||||||||||||
| 54 | $content | ||||||||||||||||||||||||||||
| 55 | </pre> | ||||||||||||||||||||||||||||
| 56 | EOT | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =head2 build_meta | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | Fill in the meta-data for this file. | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =cut | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub build_meta { | ||||||||||||||||||||||||||
|
Subroutine
build_meta: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | my $meta = $self->SUPER::build_meta(); | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # add the wordcount to the default meta | ||||||||||||||||||||||||||||
| 71 | 0 | $meta->{wordcount} = $self->wordcount; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | return $meta; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =head2 wordcount | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | Calculate the word-count of the content. | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =cut | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub wordcount { | ||||||||||||||||||||||||||
|
Subroutine
wordcount: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if (!exists $self->{wordcount}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||
| 86 | 0 | my $content = $self->raw(); | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | # count the words in the content | ||||||||||||||||||||||||||||
| 89 | 0 | $content =~ s/<[^>]+>/ /gs; # remove html tags | |||||||||||||||||||||||||||
| 90 | # Remove everything but letters + spaces | ||||||||||||||||||||||||||||
| 91 | # This is so that things like apostrophes don't make one | ||||||||||||||||||||||||||||
| 92 | # word count as two words | ||||||||||||||||||||||||||||
| 93 | 0 | $content =~ s/[^\w\s]//gs; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | my @matches = ($content =~ m/\b[\w]+/gs); | |||||||||||||||||||||||||||
| 96 | 0 | $self->{wordcount} = scalar @matches; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | return $self->{wordcount}; | |||||||||||||||||||||||||||
| 100 | } # wordcount | ||||||||||||||||||||||||||||
| 101 | 1 | 1; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | __END__ | ||||||||||||||||||||||||||||