App-sdview

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

Revision history for App-sdview

0.20    2024-10-18
        [CHANGES]
         * List the recognised parser or output types and exit if requesting
           a type named '?'

        [BUGFIXES]
         * Account for the space between line leader and paragraph content
           when testing if it will fit on one line (RT156204)
         * Ensure that override logic of $DEFAULT_OUTPUT still works

0.19    2024-10-07
        [CHANGES]
         * Experimental support for tables in Pod files, in a choice of
           different syntaxes. Not all of them will eventually be kept, this
           is largely a test to see what people like.
         * Also autodetect Pod verbatim blocks if they begin with a shebang
           line that mentions `perl`

        [BUGFIXES]

bin/sdview  view on Meta::CPAN


use v5.14;
use warnings;

use App::sdview;

use Getopt::Long;

GetOptions(
   'format|f=s' => \my $FORMAT,
   'output|t=s' => \my $OUTPUT,
   'output-option|O=s@' => \my @OUTPUT_OPTIONS,
   'highlight|h' => \my $HIGHLIGHT,
) or exit 1;

exit App::sdview->new->run(
   shift @ARGV,
   format => $FORMAT,
   output => $OUTPUT,
   output_options => \@OUTPUT_OPTIONS,
   highlight => $HIGHLIGHT,
);

=head1 NAME

F<sdview> - a terminal-based structured document viewer for Pod and other formats

=head1 SYNOPSIS

   $ sdview my-document.pod

lib/App/sdview.pm  view on Meta::CPAN

rendering of the document via the F<less> pager, but it can also output
plaintext, Pod, Markdown.

   $ sdview Some::Module -o plain > module.txt

   $ sdview Some::Module -o Markdown > module.md

=cut

# Permit loaded output modules to override
our $DEFAULT_OUTPUT = "terminal";

use Module::Pluggable
   search_path => "App::sdview::Parser",
   sub_name    => "PARSERS",
   inner       => 0,
   require     => 1;

use Module::Pluggable
   search_path => "App::sdview::Output",
   sub_name    => "OUTPUTS",
   inner       => 0,
   require     => 1;

# Must call this *before* ->run entersub so that DEFAULT_OUTPUT is overridden properly
my @OUTPUT_CLASSES = OUTPUTS();

method run ( $file,
   :$format = undef,
   :$output //= $DEFAULT_OUTPUT,
   :$highlight = 0,
   :$output_options //= [],
   %opts
) {
   my @PARSER_CLASSES = sort { $a->sort_order <=> $b->sort_order } PARSERS();

   if( ( $format // "" ) eq "?" ) {
      say "Parser format types:";
      $_->can( "format" ) and say "  " . $_->format . "  (provided by $_)"
         for @PARSER_CLASSES;
      exit 0;
   }
   if( ( $output // "" ) eq "?" ) {
      say "Output format types:";
      $_->can( "format" ) and say "  " . $_->format . "  (provided by $_)"
         for @OUTPUT_CLASSES;
      exit 0;
   }

   if( -f( my $configpath = "$ENV{HOME}/.sdviewrc" ) ) {
      App::sdview::Style->load_config( $configpath );
   }

   my %output_options = map {
      map { m/^(.*?)=(.*)$/ ? ( $1 => $2 ) : ( $_ => !!1 ) } split m/,/, $_;
   } $output_options->@*;

lib/App/sdview.pm  view on Meta::CPAN


      defined $file or
         die "Unable to find a file for '$name'\n";
   }

   $parser_class //= do {
      first { $_->can_parse_file( $file ) } @PARSER_CLASSES or
         die "Unable to find a handler for $file\n";
   };

   my $output_class = first { $_->can( "format" ) and $_->format eq $output } @OUTPUT_CLASSES or
      die "Unrecognised output name $output\n";

   my @paragraphs = $parser_class->new->parse_file( $file );

   if( $highlight ) {
      apply_highlights( $_ ) for @paragraphs;
   }

   # TODO: unrecognised output option key names will not look very neat here
   $output_class->new( %output_options )->output( @paragraphs );



( run in 0.430 second using v1.01-cache-2.11-cpan-4e96b696675 )