Perl6::Pod::Directive::alias - synonyms for longer Pod sequences


Perl6-Pod documentation Contained in the Perl6-Pod distribution.

Index


Code Index:

NAME

Top

Perl6::Pod::Directive::alias - synonyms for longer Pod sequences

SYNOPSIS

Top



    =alias PROGNAME    Earl Irradiatem Evermore
    =alias VENDOR      4D Kingdoms
    =alias TERMS_URLS  =item L<http://www.4dk.com/eie>
    =                  =item L<http://www.4dk.co.uk/eie.io/>
    =                  =item L<http://www.fordecay.ch/canttouchthis>

    The use of A<PROGNAME> is subject to the terms and conditions
    laid out by A<VENDOR>, as specified at:

        A<TERMS_URL>







DESCRIPTION

Top

The =alias directive provides a way to define lexically scoped synonyms for longer Pod sequences, (meta)object declarators from the code, or even entire chunks of ambient source. These synonyms can then be inserted into subsequent Pod using the formatting code|Alias placements.

Note that =alias is a fundamental Pod directive, like =begin or =for; there are no equivalent paragraph or delimited forms.

There are two forms of =alias directive: macro aliases and contextual aliases. Both forms are lexically scoped to the surrounding Pod block.

SEE ALSO

Top

http://zag.ru/perl6-pod/S26.html, Perldoc Pod to HTML converter: http://zag.ru/perl6-pod/, Perl6::Pod::Lib

AUTHOR

Top

Zahatski Aliaksandr, <zag@cpan.org>

COPYRIGHT AND LICENSE

Top


Perl6-Pod documentation Contained in the Perl6-Pod distribution.
package Perl6::Pod::Directive::alias;

#$Id$

use warnings;
use strict;
use Perl6::Pod::Block;
use base 'Perl6::Pod::Block';

sub new {
    my ( $class, %args ) = @_;
    my $self = $class->SUPER::new( %args, parent_context => 1 );
}

sub start {
    my $self = shift;
    my ( $parser, $attr ) = @_;
    $self->delete_element->skip_content;
    my @lines = split( /[\n\r]/, $self->context->custom->{_RAW_} );
    my $first_line_ident;
    my @res = ();
    my $alias_name;

    foreach my $line (@lines) {
        unless ($first_line_ident) {

            #check lengh first line
            $line =~ m/^\s*(=alias\s+(\w+)\s+)(.*)/
              or die 'Bad =alias at line: '
              . $self->context->custom->{_line_num_};
            $first_line_ident = length($1);
            $alias_name       = $2;

            #save first line
            push @res, $3;
            next;
        }

        #not first line
        $line =~ m/^\s*(=\s+)(.*)/
          or die "Bad line in alias block "
          . $self->context->custom->{_line_num_};
        my $text = $2;

        #save ident
        if ( length($1) > $first_line_ident ) {
            $text = " " x ( length($1) - $first_line_ident ) . $text;
        }
        push @res, $text;
    }

    $parser->current_context->{_alias}->{$alias_name} = join "\n", @res;
}
1;
__END__