| 1 | package XML::Grammar::Fortune; | ||
| 2 | $XML::Grammar::Fortune::VERSION = '0.1001'; | ||
| 3 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 2 | ▶ | use Fatal (qw(open)); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 2 | ▶ | use MooX qw/late/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 2 | ▶ | use XML::GrammarBase::Role::RelaxNG v0.2.2; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 0 | ▶ | use XML::GrammarBase::Role::XSLT v0.2.2; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 12 | |||
| 13 | with('XML::GrammarBase::Role::RelaxNG'); | ||
| 14 | with XSLT( output_format => 'html' ); | ||
| 15 | |||
| 16 | has '+module_base' => ( default => 'XML-Grammar-Fortune' ); | ||
| 17 | has '+rng_schema_basename' => ( default => 'fortune-xml.rng' ); | ||
| 18 | |||
| 19 | has '+to_html_xslt_transform_basename' => | ||
| 20 | ( default => 'fortune-xml-to-html.xslt' ); | ||
| 21 | |||
| 22 | has '_mode' => ( is => 'rw', init_arg => 'mode' ); | ||
| 23 | has '_output_mode' => ( is => 'rw', init_arg => 'output_mode', ); | ||
| 24 | |||
| 25 | |||
| 26 | sub run | ||
| 27 | { | ||
| 28 | my $self = shift; | ||
| 29 | my $args = shift; | ||
| 30 | |||
| 31 | my $xslt_params = $args->{'xslt_params'} || {}; | ||
| 32 | |||
| 33 | my $output = $args->{'output'}; | ||
| 34 | my $input = $args->{'input'}; | ||
| 35 | |||
| 36 | my $mode = $self->_mode(); | ||
| 37 | |||
| 38 | if ( $mode eq "validate" ) | ||
| 39 | { | ||
| 40 | return $self->rng_validate_file($input); | ||
| 41 | } | ||
| 42 | elsif ( $mode eq "convert_to_html" ) | ||
| 43 | { | ||
| 44 | my $translate = sub { | ||
| 45 | my ( $medium, $encoding ) = @_; | ||
| 46 | |||
| 47 | return $self->perform_xslt_translation( | ||
| 48 | { | ||
| 49 | output_format => 'html', | ||
| 50 | source => { file => $input }, | ||
| 51 | output => $medium, | ||
| 52 | encoding => $encoding, | ||
| 53 | xslt_params => $xslt_params, | ||
| 54 | } | ||
| 55 | ); | ||
| 56 | }; | ||
| 57 | if ( $self->_output_mode() eq "string" ) | ||
| 58 | { | ||
| 59 | $$output .= $translate->( 'string', 'bytes' ); | ||
| 60 | } | ||
| 61 | else | ||
| 62 | { | ||
| 63 | $translate->( { file => $output }, 'utf8' ); | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | return; | ||
| 68 | } | ||
| 69 | |||
| 70 | 1; # End of XML::Grammar::Fortune | ||
| 71 | |||
| 72 | __END__ | ||