Text::SmartLinks - connecting test files with pod documentation


Text-SmartLinks documentation  | view source Contained in the Text-SmartLinks distribution.

Index


NAME

Top

Text::SmartLinks - connecting test files with pod documentation

SYNOPSIS

Top

  smartlinks.pl t/*/*.t t/*/*/*.t
  smartlinks.pl --dir t
  smartlinks.pl --css foo.css --out-dir=public_html t/syntax/*.t
  smartlinks.pl --check t/*/*.t t/*/*/*.t
  smartlinks.pl --check t/some/test.t
  smartlinks.pl --missing t/*/*.t t/*/*/*.t

If in the root directory of a CPAN package type the following:

  smartlinks.pl --pod-dir lib/ --dir t/ --out-dir html/ --index

In the root of Text::SmartLinks type in the following:

  perl -Ilib script/smartlinks.pl --pod-dir lib/ --dir t/ --out-dir html/ --index

DESCRIPTION

Top

The plan is to change the Text::SmartLinks module and write a new smartlinks.pl script so it will be usable in any Perl 5 or Perl 6 project to generate the HTML pages combining the POD content from the .pod and .pm files and test scripts.

In addition the script should be able to generate further reports in HTML format that help the developers.

The usage should default to parsing the files in lib/ for documentation and the .t files in the t/ subdirectory.

Requirements

Top

Process both Perl 5 and Perl 6 test files in an arbitraty directory to collect smartlinks. Default should be either the local t/ directory or the t/spec directory of Pugs (for historical reasons).

Process .pod and .pm files (but maybe other files as well) with either Perl 5 or Perl 6 pod in them and with possibly also code in them.

Smartlinks should be able to say the name of the document where they link to.

    L<Smolder/Text of head1>
    L<Smolder::Util/Text o head2>

Map to either Smolder.pm or Smolder.pod and Smolder/Util.pm or Smolder/Util.pod

Need special cases for the Perl 6 documentation so the smartlinks can have the following links pointing to S06-routines.pod and S32-setting-library/Abstraction.pod

    L<S06/Blocks>
    L<S32::Abstraction>




Old Design Decisions

Top

Smartlink Syntax

Top

Basic Algorithm

Top

1.

We scan over all the specified .t files; collect smartlinks and positional info about the test code snippets as we go. When all these work have been finished, we obtain a tree structure, which is named $linktree in the source code.

To make this tree minimal, we only store the .t file name and line numbers, rather than the snippets' source code itself.

The structure of $linktree is like this:

    {
      'S12' => {
        'Traits' => [
          [
            undef,
            [
              't/oo/traits/basic.t',
              '13',
              '38'
            ]
          ],
          [
            '/If you say/',
            [
              't/oo/delegation.t',
              '56',
              '69'
            ]
          ],
        ],
      },
      'S02' => {
        'Whitespace and Comments' => [
          [
            '"Embedded comments" "#" plus any bracket',
            [
              't/syntax/comments.t',
              10,
              48
            ]
          ],
        ]
      }
    }

This step is mostly done by sub process_t_file.

2.

We process the synopsis .pod files one by one and generate HTML files integrated with test code snippets using the $linktree structure discussed above.

This is mostly done by sub process_pod_file.

Because it is an enormous step, we can further divide it into several sub steps:

  • We parse each .pod into a tree, which is known as $podtree in the source code. (See sub parse_pod.)

    The structure of $podtree looks like this:

        {
          'Names and Variables' => [
            '=over 4' . "\n",
            '=item *' . "\n",
            'The C<$Package\'var> syntax is gone.  Use C<$Package::var> instead.' . "\n",
            '=item *' . "\n",
            'Perl 6 includes a system of B<sigils> to mark the fundamental' . "\n".
                'structural type of a variable:' . "\n",
            ...
          ],
          ...
        }
    
    
  • We look up every related smartlink from every $podtree, generate .t code snippets along the way, and insert placeholders (like "_SMART_LINK_3" into the corresponding $podtree. (See subs parse_pattern, process_paragraph, and gen_code_snippet.)
  • Now we emit Pod source back from the modified $podtree's. (See sub emit_pod.)
  • After that, we generate HTML source from the Pod source with snippet placeholders using Pod::Simple::HTML. (See sub gen_html.)
  • At last, we replace every snippet placeholders in the HTML source with the real snippet code (also in HTML format).

SEE ALSO

Top

METHODS

Top

new

Constructor, can get a HASH reference as it is a base class of Class::Accessor

process_test_files

Gets a list of .t test files, calls process_t_file on each on of them.

process_t_file

Gets a path to a .t file, reads line by line and collects the smartlinks in it to a hash structure using the add_link function.

parse_pattern

Convert patterns used in 00-smartlinks.to perl 5 regexes

process_paragraph

Process paragraphs of the pod file: unwrap lines, strip POD tags, and etc.

gen_code_snippet

Gets a triplet of [file, from, to] and generates an HTML snippet from that section of the given file.

Note that this function has been optimized for space rather than time.

get_javascript

Returns the content of the smartlink.js file. Probably we should just copy the .js file to the html directory and not embed it.

AUTHOR

Top

Agent Zhang (<agentzh@gmail.com>) wrote the initial implementation, getting help from many others in the Pugs team.

Current maintainer: The Pugs team

COPYRIGHT

Top

LICENSE

Top

Text::SmartLinks is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. (Note that, unlike the Artistic License 1.0, version 2.0 is GPL compatible by itself, hence there is no benefit to having an Artistic 2.0 / GPL disjunction.)


Text-SmartLinks documentation  | view source Contained in the Text-SmartLinks distribution.