PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/Pod-Perldoc-3.17/lib/Pod/Perldoc/BaseTo.pm

#
Perl | 152 lines | 128 code | 19 blank | 5 comment | 3 complexity | 7d4be46d91e052fb94ffa0a55b223e86 MD5 | raw file
  1. package Pod::Perldoc::BaseTo;
  2. use strict;
  3. use warnings;
  4. use vars qw($VERSION);
  5. $VERSION = '3.17';
  6. use Carp qw(croak carp);
  7. use Config qw(%Config);
  8. use File::Spec::Functions qw(catfile);
  9. sub is_pageable { '' }
  10. sub write_with_binmode { 1 }
  11. sub output_extension { 'txt' } # override in subclass!
  12. # sub new { my $self = shift; ... }
  13. # sub parse_from_file( my($class, $in, $out) = ...; ... }
  14. #sub new { return bless {}, ref($_[0]) || $_[0] }
  15. # this is also in Perldoc.pm, but why look there when you're a
  16. # subclass of this?
  17. sub TRUE () {1}
  18. sub FALSE () {return}
  19. BEGIN {
  20. *is_vms = $^O eq 'VMS' ? \&TRUE : \&FALSE unless defined &is_vms;
  21. *is_mswin32 = $^O eq 'MSWin32' ? \&TRUE : \&FALSE unless defined &is_mswin32;
  22. *is_dos = $^O eq 'dos' ? \&TRUE : \&FALSE unless defined &is_dos;
  23. *is_os2 = $^O eq 'os2' ? \&TRUE : \&FALSE unless defined &is_os2;
  24. *is_cygwin = $^O eq 'cygwin' ? \&TRUE : \&FALSE unless defined &is_cygwin;
  25. *is_linux = $^O eq 'linux' ? \&TRUE : \&FALSE unless defined &is_linux;
  26. *is_hpux = $^O =~ m/hpux/ ? \&TRUE : \&FALSE unless defined &is_hpux;
  27. *is_openbsd = $^O =~ m/openbsd/ ? \&TRUE : \&FALSE unless defined &is_openbsd;
  28. }
  29. sub _perldoc_elem {
  30. my($self, $name) = splice @_,0,2;
  31. if(@_) {
  32. $self->{$name} = $_[0];
  33. } else {
  34. $self->{$name};
  35. }
  36. }
  37. sub debugging {
  38. my( $self, @messages ) = @_;
  39. ( defined(&Pod::Perldoc::DEBUG) and &Pod::Perldoc::DEBUG() )
  40. }
  41. sub debug {
  42. my( $self, @messages ) = @_;
  43. return unless $self->debugging;
  44. print STDERR map { "DEBUG $_" } @messages;
  45. }
  46. sub warn {
  47. my( $self, @messages ) = @_;
  48. carp join "\n", @messages, '';
  49. }
  50. sub die {
  51. my( $self, @messages ) = @_;
  52. croak join "\n", @messages, '';
  53. }
  54. sub _get_path_components {
  55. my( $self ) = @_;
  56. my @paths = split /\Q$Config{path_sep}/, $ENV{PATH};
  57. return @paths;
  58. }
  59. sub _find_executable_in_path {
  60. my( $self, $program ) = @_;
  61. my @found = ();
  62. foreach my $dir ( $self->_get_path_components ) {
  63. my $binary = catfile( $dir, $program );
  64. $self->debug( "Looking for $binary\n" );
  65. next unless -e $binary;
  66. unless( -x $binary ) {
  67. $self->warn( "Found $binary but it's not executable. Skipping.\n" );
  68. next;
  69. }
  70. $self->debug( "Found $binary\n" );
  71. push @found, $binary;
  72. }
  73. return @found;
  74. }
  75. 1;
  76. __END__
  77. =head1 NAME
  78. Pod::Perldoc::BaseTo - Base for Pod::Perldoc formatters
  79. =head1 SYNOPSIS
  80. package Pod::Perldoc::ToMyFormat;
  81. use base qw( Pod::Perldoc::BaseTo );
  82. ...
  83. =head1 DESCRIPTION
  84. This package is meant as a base of Pod::Perldoc formatters,
  85. like L<Pod::Perldoc::ToText>, L<Pod::Perldoc::ToMan>, etc.
  86. It provides default implementations for the methods
  87. is_pageable
  88. write_with_binmode
  89. output_extension
  90. _perldoc_elem
  91. The concrete formatter must implement
  92. new
  93. parse_from_file
  94. =head1 SEE ALSO
  95. L<perldoc>
  96. =head1 COPYRIGHT AND DISCLAIMERS
  97. Copyright (c) 2002-2007 Sean M. Burke.
  98. This library is free software; you can redistribute it and/or modify it
  99. under the same terms as Perl itself.
  100. This program is distributed in the hope that it will be useful, but
  101. without any warranty; without even the implied warranty of
  102. merchantability or fitness for a particular purpose.
  103. =head1 AUTHOR
  104. Current maintainer: Mark Allen C<< <mallen@cpan.org> >>
  105. Past contributions from:
  106. brian d foy C<< <bdfoy@cpan.org> >>
  107. Adriano R. Ferreira C<< <ferreira@cpan.org> >>,
  108. Sean M. Burke C<< <sburke@cpan.org> >>
  109. =cut