| 1 | package Rhetoric::Formatters; | ||||||||||
| 2 | 1 | ▶ | use common::sense; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use aliased 'Squatting::H'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Memoize; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Ouch; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Method::Signatures::Simple; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | #memoize('_load'); | ||||||||||
| 10 | 0 | ▶ | sub _load { | ||||||||
|
Subroutine
_load: not called CC=2 SCAR=17.9
| |||||||||||
| 11 | 0 | my $module = shift; | |||||||||
| 12 | 0 | my $formatter = shift; | |||||||||
| 13 | 0 | my $path = $module; | |||||||||
| 14 | 0 | $path =~ s{::}{/}g; | |||||||||
| 15 | 0 | $path .= ".pm"; | |||||||||
| 16 | 0 | my $module_loaded = 0; | |||||||||
| 17 | 0 | ▶ | try { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 18 | 0 | require($path); | |||||||||
| 19 | 0 | $module_loaded = 1; | |||||||||
| 20 | 0 | ▶ | } catch { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 21 | 0 | ouch('RequireFailed', "Could not load $module: $_"); | |||||||||
| 22 | 0 | }; | |||||||||
| 23 | 0 | ▶ | return $formatter->() if $module_loaded; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | our $F = H->new({ | ||||||||||
| 27 | raw => method($t) { | ||||||||||
| 28 | $t | ||||||||||
| 29 | }, | ||||||||||
| 30 | |||||||||||
| 31 | pod => method($t) { | ||||||||||
| 32 | my $pod = _load('Pod::Simple::HTML', sub { | ||||||||||
| 33 | my $pod = Pod::Simple::HTML->new; | ||||||||||
| 34 | $pod->index(0); | ||||||||||
| 35 | return $pod; | ||||||||||
| 36 | }); | ||||||||||
| 37 | my $out; | ||||||||||
| 38 | $pod->output_string(\$out); | ||||||||||
| 39 | $pod->parse_string_document("=pod\n\n$t\n\n=cut\n"); | ||||||||||
| 40 | $out =~ s/^.*<!-- start doc -->//s; | ||||||||||
| 41 | $out =~ s/<!-- end doc -->.*$//s; | ||||||||||
| 42 | #$out =~ s/^(.*%3A%3A.*)$/my $x = $1; ($x =~ m{indexItem}) ? 1 : $x =~ s{%3A%3A}{\/}g; $x/gme; | ||||||||||
| 43 | return $out; | ||||||||||
| 44 | }, | ||||||||||
| 45 | |||||||||||
| 46 | textile => method($t) { | ||||||||||
| 47 | my $tt = _load('Text::Textile', sub { | ||||||||||
| 48 | return Text::Textile->new( | ||||||||||
| 49 | disable_html => 1 | ||||||||||
| 50 | ); | ||||||||||
| 51 | }); | ||||||||||
| 52 | return $tt->process($t); | ||||||||||
| 53 | }, | ||||||||||
| 54 | |||||||||||
| 55 | markdown => method($t) { | ||||||||||
| 56 | my $md = _load('Text::Markdown', sub { | ||||||||||
| 57 | # TODO - figure out what options we want to set for markdown | ||||||||||
| 58 | return Text::Markdown->new(); | ||||||||||
| 59 | }); | ||||||||||
| 60 | return $md->markdown($t); | ||||||||||
| 61 | }, | ||||||||||
| 62 | }); | ||||||||||
| 63 | |||||||||||
| 64 | 1; | ||||||||||
| 65 | |||||||||||
| 66 | __END__ | ||||||||||