File: summary.pm

package info (click to toggle)
libpod-abstract-perl 0.20-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, trixie
  • size: 248 kB
  • sloc: perl: 2,006; makefile: 2
file content (85 lines) | stat: -rw-r--r-- 2,118 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package Pod::Abstract::Filter::summary;
use strict;

use base qw(Pod::Abstract::Filter);
use Pod::Abstract::BuildNode qw(node);

our $VERSION = '0.20';

=head1 NAME

Pod::Abstract::Filter::summary - paf command to show document outline,
with short examples.

=cut

sub filter {
    my $self = shift;
    my $pa = shift;
    
    my $summary = node->root;
    my $summ_block = node->head1('Summary');
    $summary->nest($summ_block);
    
    $self->summarise_headings($pa,$summ_block);
    $summ_block->nest(node->text("\n"));
    $summ_block->coalesce_body(':text');
    
    return $summary;
}

sub summarise_headings {
    my $self = shift;
    my $pa = shift;
    my $summ_block = shift;
    my $depth = shift;
    $depth = 1 unless defined $depth;
    
    my @headings = $pa->select('/[@heading]');
    my @items = $pa->select('/over/item[@label =~ {[a-zA-Z]+}]'); # Labels that have strings
    
    unshift @headings, @items;
    
    foreach my $head (@headings) {
        my ($hdg) = $head->select('@heading');
        if($head->type eq 'item') {
            ($hdg) = $head->select('@label');
        }
        my $hdg_text = $hdg->text;
        $summ_block->push(
            node->text(("  " x $depth) . $hdg_text . "\n")
            );
        if($hdg_text =~ m/^[0-9a-zA-Z_ ]+$/) {
            my ($synopsis) = $head->select("//:verbatim[. =~ {$hdg_text}](0)");
            if($synopsis) {
                my $synop_body = $synopsis->body;
                $synop_body =~ s/[\r\n]//sg;
                $synop_body =~ s/[\t ]+/ /g;
                $synop_body =~ s/^ //g;
                
                $summ_block->push(
                    node->text(
                        ("  " x $depth) . " \\ " . $synop_body . "\n"
                    )
                );
            }
        }
            
        $self->summarise_headings($head, $summ_block, $depth + 1);
    }
}

=head1 AUTHOR

Ben Lilburne <bnej@mac.com>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2009 Ben Lilburne

This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;