[Rt-commit] rt branch 5.0/convert-to-pod-simple created. rt-5.0.3-130-g91b804b245

BPS Git Server git at git.bestpractical.com
Fri Nov 4 19:09:44 UTC 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/convert-to-pod-simple has been created
        at  91b804b245e8aec92a98b368c84a75ec8f6eeaed (commit)

- Log -----------------------------------------------------------------
commit 91b804b245e8aec92a98b368c84a75ec8f6eeaed
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Nov 4 13:50:41 2022 -0400

    Remove unwanted anchor tags from head elements

diff --git a/lib/RT/Shredder/POD.pm b/lib/RT/Shredder/POD.pm
index 70901bf69e..723f6e4d53 100644
--- a/lib/RT/Shredder/POD.pm
+++ b/lib/RT/Shredder/POD.pm
@@ -276,4 +276,133 @@ sub version_tag_comment {
     # Don't need version details inside the RT HTML page.
     return '';
 }
+
+# This override is to remove the links around head elements since we
+# don't have an index and they aren't used in the RT page.
+
+# Would prefer not to copy this entire method for this small change
+# but it's embedded in the logic.
+
+# TODO: remove this if Pod::Simple::HTML adds a way to suppress
+# the links via config somehow
+
+$Pod::Simple::HTML::Tagmap{'no-a/head1'} = "</h1>\n";
+$Pod::Simple::HTML::Tagmap{'no-a/head2'} = "</h2>\n";
+$Pod::Simple::HTML::Tagmap{'no-a/head3'} = "</h3>\n";
+$Pod::Simple::HTML::Tagmap{'no-a/head4'} = "</h4>\n";
+$Pod::Simple::HTML::Tagmap{'no-a/head5'} = "</h5>\n";
+$Pod::Simple::HTML::Tagmap{'no-a/head6'} = "</h6>\n";
+
+sub _do_middle_main_loop {
+  my $self = $_[0];
+  my $fh = $self->{'output_fh'};
+  my $tagmap = $self->{'Tagmap'};
+
+  $self->__adjust_html_h_levels;
+
+  my($token, $type, $tagname, $linkto, $linktype);
+  my @stack;
+  my $dont_wrap = 0;
+
+  while($token = $self->get_token) {
+
+    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+    if( ($type = $token->type) eq 'start' ) {
+      if(($tagname = $token->tagname) eq 'L') {
+        $linktype = $token->attr('type') || 'insane';
+
+        $linkto = $self->do_link($token);
+
+        if(defined $linkto and length $linkto) {
+          &Pod::Simple::HTML::esc($linkto);
+            #   (Yes, SGML-escaping applies on top of %-escaping!
+            #   But it's rarely noticeable in practice.)
+          print $fh qq{<a href="$linkto" class="podlink$linktype"\n>};
+        } else {
+          print $fh "<a>"; # Yes, an 'a' element with no attributes!
+        }
+
+      } elsif ($tagname eq 'item-text' or $tagname =~ m/^head\d$/s) {
+        print $fh $tagmap->{$tagname} || next;
+
+        my @to_unget;
+        while(1) {
+          push @to_unget, $self->get_token;
+          last if $to_unget[-1]->is_end
+              and $to_unget[-1]->tagname eq $tagname;
+
+          # TODO: support for X<...>'s found in here?  (maybe hack into linearize_tokens)
+        }
+
+        my $name = $self->linearize_tokens(@to_unget);
+        $name = $self->do_section($name, $token) if defined $name;
+
+        # Code that adds anchor tags to head elements removed here
+
+        $self->unget_token(@to_unget);
+
+      } elsif ($tagname eq 'Data') {
+        my $next = $self->get_token;
+        next unless defined $next;
+        unless( $next->type eq 'text' ) {
+          $self->unget_token($next);
+          next;
+        }
+        &Pod::Simple::DEBUG and print STDERR "    raw text ", $next->text, "\n";
+        # The parser sometimes preserves newlines and sometimes doesn't!
+        (my $text = $next->text) =~ s/\n\z//;
+        print $fh $text, "\n";
+        next;
+
+      } else {
+        if( $tagname =~ m/^over-/s ) {
+          push @stack, '';
+        } elsif( $tagname =~ m/^item-/s and @stack and $stack[-1] ) {
+          print $fh $stack[-1];
+          $stack[-1] = '';
+        }
+        print $fh $tagmap->{$tagname} || next;
+        ++$dont_wrap if $tagname eq 'Verbatim' or $tagname eq "VerbatimFormatted"
+          or $tagname eq 'X';
+      }
+
+    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+    } elsif( $type eq 'end' ) {
+      if( ($tagname = $token->tagname) =~ m/^over-/s ) {
+        if( my $end = pop @stack ) {
+          print $fh $end;
+        }
+      } elsif( $tagname =~ m/^item-/s and @stack) {
+        $stack[-1] = $tagmap->{"/$tagname"};
+        if( $tagname eq 'item-text' and defined(my $next = $self->get_token) ) {
+          $self->unget_token($next);
+          if( $next->type eq 'start' ) {
+            print $fh $tagmap->{"/item-text"},$tagmap->{"item-body"};
+            $stack[-1] = $tagmap->{"/item-body"};
+          }
+        }
+        next;
+      }
+
+      if ($tagname =~ m/^head\d$/s) {
+          print $fh $tagmap->{"no-a/$tagname"} || next;
+      }
+      else {
+          print $fh $tagmap->{"/$tagname"} || next;
+      }
+
+      --$dont_wrap if $tagname eq 'Verbatim' or $tagname eq 'X';
+
+    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+    } elsif( $type eq 'text' ) {
+      &Pod::Simple::HTML::esc($type = $token->text);  # reuse $type, why not
+      $type =~ s/([\?\!\"\'\.\,]) /$1\n/g unless $dont_wrap;
+      print $fh $type;
+    }
+
+  }
+  return 1;
+}
+
+
 1;

commit abe3ffa0d9c38cccc871d6e356ea9b73e2ab678b
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Nov 4 13:49:32 2022 -0400

    Clear unneeded anchors and HTML comments

diff --git a/lib/RT/Shredder/POD.pm b/lib/RT/Shredder/POD.pm
index fe10ae16bb..70901bf69e 100644
--- a/lib/RT/Shredder/POD.pm
+++ b/lib/RT/Shredder/POD.pm
@@ -56,6 +56,7 @@ sub plugin_html
 {
     my ($file, $out_fh) = @_;
     my $parser = RT::Shredder::POD::HTML->new;
+    $parser->top_anchor('');
     $parser->output_fh($out_fh);
     $parser->select('SYNOPSIS', 'ARGUMENTS', 'USAGE');
     $parser->parse_file( $file );
@@ -95,6 +96,7 @@ sub arguments_help {
 
     my $text;
     my $parser = RT::Shredder::POD::HTML->new;
+    $parser->top_anchor('');
     $parser->output_string(\$text);
     $parser->select('ARGUMENTS');
     $parser->parse_file( $file );
@@ -270,4 +272,8 @@ sub get_token {
     return $token;
 }
 
+sub version_tag_comment {
+    # Don't need version details inside the RT HTML page.
+    return '';
+}
 1;

commit 88991e184710d65a2d31e0937a651a9425d8ffaf
Author: Brian Conry <bconry at bestpractical.com>
Date:   Wed Oct 5 14:39:12 2022 -0500

    Remove dependency on Pod::Select
    
    This change removes the explicit dependency on Pod::Select.

diff --git a/docs/UPGRADING-5.0 b/docs/UPGRADING-5.0
index 9991928fcd..58d59aefcf 100644
--- a/docs/UPGRADING-5.0
+++ b/docs/UPGRADING-5.0
@@ -487,6 +487,11 @@ additional defense against CSRF attacks in some browsers.  See
 L<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite>
 for more details on valid values, their meaning, and browser support.
 
+=item * Removed dependency on Pod::Select
+
+We no longer depend on the Pod::Select Perl module since it has been deprecated
+following its removal from the Perl core.
+
 =back
 
 =cut
diff --git a/etc/cpanfile b/etc/cpanfile
index aaa8cb969f..1f308e7742 100644
--- a/etc/cpanfile
+++ b/etc/cpanfile
@@ -69,7 +69,6 @@ requires 'Net::IP';
 requires 'Parallel::ForkManager';
 requires 'Plack', '>= 1.0002';
 requires 'Plack::Handler::Starlet';
-requires 'Pod::Select';
 requires 'Regexp::Common';
 requires 'Regexp::Common::net::CIDR';
 requires 'Regexp::IPv6';

commit cb29990d761ea70af505b7320a18a4a35693c7f3
Author: Brian Conry <bconry at bestpractical.com>
Date:   Wed Oct 5 14:30:03 2022 -0500

    Replace Pod::Select HTML generation
    
    Prior to this change, RT::Shredder::POD used Pod::Select to generate
    HTML versions of help information for the Admin shredder pages in the RT
    UI.
    
    Since Pod::Select is deprecated and going to be removed from Perl CORE,
    it has been replaced with Pod::Simple::HTML.

diff --git a/lib/RT/Shredder/POD.pm b/lib/RT/Shredder/POD.pm
index 4b4d78a4d9..fe10ae16bb 100644
--- a/lib/RT/Shredder/POD.pm
+++ b/lib/RT/Shredder/POD.pm
@@ -51,14 +51,14 @@ package RT::Shredder::POD;
 use strict;
 use warnings;
 use Pod::Simple::Text;
-use Pod::Select;
 
 sub plugin_html
 {
     my ($file, $out_fh) = @_;
     my $parser = RT::Shredder::POD::HTML->new;
+    $parser->output_fh($out_fh);
     $parser->select('SYNOPSIS', 'ARGUMENTS', 'USAGE');
-    $parser->parse_from_file( $file, $out_fh );
+    $parser->parse_file( $file );
     return;
 }
 
@@ -94,18 +94,19 @@ sub arguments_help {
     my ($file) = @_;
 
     my $text;
-    open( my $io_handle, ">:scalar", \$text )
-        or die "Can't open scalar for write: $!";
     my $parser = RT::Shredder::POD::HTML->new;
+    $parser->output_string(\$text);
     $parser->select('ARGUMENTS');
-    $parser->parse_from_file( $file, $io_handle );
+    $parser->parse_file( $file );
 
     my $arguments_help = {};
 
-    while( $text=~ m{<h4[^>]*>    # argument description starts with an h4 title
-                       \s*(\S*)   #   argument name ($1)
+    while( $text=~ m{<h4[^>]*>         # argument description starts with an h4 title
+                       \s*<a\s*[^>]*>  # is enclosed in an <a> tag
+                       \s*(\S*)        #   argument name ($1)
                          \s*-\s*
-                       ([^<]*)    #   argument type ($2)
+                       ([^<]*)         #   argument type ($2)
+                       \s*</a>\s*      # closing the <a>
                      </h4>\s*
                        (?:<p[^>]*>\s*
                        (.*?)      #   help: the first paragraph of the POD     ($3)
@@ -192,61 +193,81 @@ sub end_Verbatim {
 1;
 
 package RT::Shredder::POD::HTML;
-use base qw(Pod::Select);
+use base qw(Pod::Simple::HTML);
 
-sub command
-{
-    my( $self, $command, $paragraph, $line_num ) = @_;
+(our $VERSION = $RT::VERSION) =~ s/^(\d+\.\d+).*/$1/;
 
-    my $tag;
-    # =head1 => h3, =head2 => h4
-    if ($command =~ /^head(\d+)$/) {
-        my $h_level = $1 + 2;
-        $tag = "h$h_level";
-    }
-    my $out_fh = $self->output_handle();
-    my $expansion = $self->interpolate($paragraph, $line_num);
-    $expansion =~ s/^\s+|\s+$//;
-    $expansion = lc( $expansion );
-    $expansion = ucfirst( $expansion );
-
-    print $out_fh "<$tag class=\"rt-general-header1\">" if $tag eq 'h3';
-    print $out_fh "<$tag class=\"rt-general-header2\">" if $tag eq 'h4';
-    print $out_fh $expansion;
-    print $out_fh "</$tag>" if $tag;
-    print $out_fh "\n";
-    return;
+sub new {
+    my $self = shift;
+    my $new = $self->SUPER::new(@_);
+
+    $new->{'Selected'} = {};
+
+    $new->html_h_level(3);
+    $new->__adjust_html_h_levels;
+    $new->{'Adjusted_html_h_levels'} = 3;
+
+    $new->_add_classes_to_types(
+        head1 => 'rt-general-header1',
+        head2 => 'rt-general-header2',
+        Para => 'rt-general-paragraph',
+    );
+
+    return $new;
 }
 
-sub verbatim
-{
-    my ($self, $paragraph, $line_num) = @_;
-    my $out_fh = $self->output_handle();
-    print $out_fh "<pre class=\"rt-general-paragraph\">";
-    print $out_fh $paragraph;
-    print $out_fh "</pre>";
-    print $out_fh "\n";
-    return;
+sub _add_classes_to_types {
+    my $self = shift;
+    my $Tagmap = $self->{'Tagmap'};
+
+    my %mods = @_;
+
+    foreach my $tagname ( keys %mods ) {
+        my $classname = $mods{$tagname};
+
+        next unless exists $Tagmap->{$tagname};
+
+        my $tagvalue = $Tagmap->{$tagname};
+
+        $tagvalue =~ s{(<\w+ class='[^']+)('>)$}{$1 $classname$2};
+        $tagvalue =~ s{(<\w+)(>)$}{$1 class='$classname'$2};
+
+        $Tagmap->{$tagname} = $tagvalue;
+    }
 }
 
-sub textblock {
-    my ($self, $paragraph, $line_num) = @_;
-    my $out_fh = $self->output_handle();
-    my $expansion = $self->interpolate($paragraph, $line_num);
-    $expansion =~ s/^\s+|\s+$//;
-    print $out_fh "<p class=\"rt-general-paragraph\">";
-    print $out_fh $expansion;
-    print $out_fh "</p>";
-    print $out_fh "\n";
+sub select {
+    my $self = shift;
+    $self->{'Selected'}{$_} = 1 for @_;
     return;
 }
 
-sub interior_sequence {
-    my ($self, $seq_command, $seq_argument) = @_;
-    ## Expand an interior sequence; sample actions might be:
-    return "<b>$seq_argument</b>" if $seq_command eq 'B';
-    return "<i>$seq_argument</i>" if $seq_command eq 'I';
-    return "<tt>$seq_argument</tt>" if $seq_command eq 'C';
-    return "<span class=\"pod-sequence-$seq_command\">$seq_argument</span>";
+sub get_token {
+    my $self = shift;
+
+    my $token = $self->SUPER::get_token();
+
+    return $token unless $token;
+
+    if (scalar keys %{ $self->{'Selected'} }) {
+        while ($token and $token->type eq 'start' and $token->tagname eq 'head1') {
+            my $next_token = $self->SUPER::get_token();
+
+            if ($next_token->type eq 'text' and not exists $self->{'Selected'}{ $next_token->text }) {
+                # discard everything up to, but not including, the start of the next head1
+                while ($next_token and ($next_token->type ne 'start' or $next_token->tagname ne 'head1')) {
+                    $next_token = $self->SUPER::get_token();
+                }
+                $token = $next_token;
+            }
+            else {
+                $self->unget_token($next_token);
+                last;
+            }
+        }
+    }
+
+    return $token;
 }
+
 1;

commit 8059837b09b034e1fac48a06a07c3878c3923c4a
Author: Brian Conry <bconry at bestpractical.com>
Date:   Tue Oct 4 21:40:07 2022 -0500

    Replace Pod::Select and Pod::PlainText for plain text
    
    Prior to this change, RT::Shredder::POD used Pod::Select and
    Pod::PlainText to generate plain-text help information for the
    command-line utility rt-shredder.
    
    Since Pod::Select is deprecated and going to be removed from Perl CORE,
    it has been replaced with Pod::Simple::Text.

diff --git a/lib/RT/Shredder/POD.pm b/lib/RT/Shredder/POD.pm
index 9d80edad53..4b4d78a4d9 100644
--- a/lib/RT/Shredder/POD.pm
+++ b/lib/RT/Shredder/POD.pm
@@ -50,8 +50,8 @@ package RT::Shredder::POD;
 
 use strict;
 use warnings;
+use Pod::Simple::Text;
 use Pod::Select;
-use Pod::PlainText;
 
 sub plugin_html
 {
@@ -65,21 +65,20 @@ sub plugin_html
 sub plugin_cli
 {
     my ($file, $out_fh, $no_name) = @_;
-    local @Pod::PlainText::ISA = ('Pod::Select', @Pod::PlainText::ISA);
-    my $parser = Pod::PlainText->new();
-    $parser->select('SYNOPSIS', 'ARGUMENTS', 'USAGE');
-    $parser->add_selection('NAME') unless $no_name;
-    $parser->parse_from_file( $file, $out_fh );
+    my $parser = RT::Shredder::POD::Text->new;
+    $parser->output_fh($out_fh);
+    $parser->select('SYNOPSIS', 'ARGUMENTS', 'USAGE', ($no_name ? () : 'Name') );
+    $parser->parse_file( $file );
     return;
 }
 
 sub shredder_cli
 {
     my ($file, $out_fh) = @_;
-    local @Pod::PlainText::ISA = ('Pod::Select', @Pod::PlainText::ISA);
-    my $parser = Pod::PlainText->new();
+    my $parser = RT::Shredder::POD::Text->new;
+    $parser->output_fh($out_fh);
     $parser->select('NAME', 'SYNOPSIS', 'USAGE', 'OPTIONS');
-    $parser->parse_from_file( $file, $out_fh );
+    $parser->parse_file( $file );
     return;
 }
 
@@ -123,6 +122,75 @@ sub arguments_help {
 
 1;
 
+package RT::Shredder::POD::Text;
+use base qw(Pod::Simple::Text);
+
+sub new {
+    my $self = shift;
+    my $new = $self->SUPER::new(@_);
+    $new->{'Suppress'} = 1;
+    $new->{'InHead1'} = 0;
+    $new->{'Selected'} = {};
+    return $new;
+}
+
+sub select {
+    my $self = shift;
+    $self->{'Selected'}{$_} = 1 for @_;
+    return;
+}
+
+sub handle_text {
+    my $self = shift;
+
+    if ($self->{'InHead1'} and exists $self->{'Selected'}{ $_[0] }) {
+        $self->{'Suppress'} = 0;
+    }
+
+    return $self->SUPER::handle_text( @_ );
+}
+
+sub start_head1 {
+    my $self = shift;
+
+    $self->{'InHead1'} = 1;
+    $self->{'Suppress'} = 1;
+
+    return $self->SUPER::start_head1( @_ );
+}
+
+sub end_head1 {
+    my $self = shift;
+
+    $self->{'InHead1'} = 0;
+
+    return $self->SUPER::end_head1( @_ );
+}
+
+sub emit_par {
+    my $self = shift;
+
+    if ($self->{'Suppress'}) {
+        $self->{'Thispara'} = '';
+        return;
+    }
+
+    return $self->SUPER::emit_par( @_ );
+}
+
+sub end_Verbatim {
+    my $self = shift;
+
+    if ($self->{'Suppress'}) {
+        $self->{'Thispara'} = '';
+        return;
+    }
+
+    return $self->SUPER::end_Verbatim( @_ );
+}
+
+1;
+
 package RT::Shredder::POD::HTML;
 use base qw(Pod::Select);
 

commit 8437f72ac87fd2f4647b8b510909f958a927b248
Author: Brian Conry <bconry at bestpractical.com>
Date:   Tue Oct 4 21:39:41 2022 -0500

    Foer -> for
    
    Fix typo in comment

diff --git a/lib/RT/Shredder/POD.pm b/lib/RT/Shredder/POD.pm
index ade9d12c5a..9d80edad53 100644
--- a/lib/RT/Shredder/POD.pm
+++ b/lib/RT/Shredder/POD.pm
@@ -83,7 +83,7 @@ sub shredder_cli
     return;
 }
 
-# Extract the help foer each argument from the plugin POD
+# Extract the help for each argument from the plugin POD
 # they must be on a =head2 line in the ARGUMENTS section of the POD
 # the return value is a hashref:
 #   keys are the argument names,

-----------------------------------------------------------------------


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list