File Coverage

blib/lib/Perl6/Pod/Directive/alias.pm
Criterion Covered Total %
statement 12 36 33.3
branch 0 8 0.0
condition n/a
subroutine 4 6 66.6
pod 0 2 0.0
total 16 52 30.7


line stmt bran cond sub pod time code
1             package Perl6::Pod::Directive::alias;
2              
3             =pod
4              
5             =head1 NAME
6              
7             Perl6::Pod::Directive::alias - synonyms for longer Pod sequences
8              
9             =head1 SYNOPSIS
10              
11              
12             =alias PROGNAME Earl Irradiatem Evermore
13             =alias VENDOR 4D Kingdoms
14             =alias TERMS_URLS =item L
15             = =item L
16             = =item L
17              
18             The use of A is subject to the terms and conditions
19             laid out by A, as specified at:
20              
21             A
22              
23              
24              
25             =head1 DESCRIPTION
26              
27             The C<=alias> directive provides a way to define lexically scoped
28             synonyms for longer Pod sequences, (meta)object declarators from the
29             code, or even entire chunks of ambient source. These synonyms can then
30             be inserted into subsequent Pod using the
31             L formatting code>|Alias placements>.
32              
33             Note that C<=alias> is a fundamental Pod directive, like C<=begin> or
34             C<=for>; there are no equivalent paragraph or delimited forms.
35              
36             There are two forms of C<=alias> directive: macro aliases and contextual
37             aliases. Both forms are lexically scoped to the surrounding Pod block.
38              
39             =cut
40              
41 3     3   15 use warnings;
  3         5  
  3         77  
42 3     3   14 use strict;
  3         5  
  3         57  
43 3     3   13 use Perl6::Pod::Block;
  3         5  
  3         76  
44 3     3   15 use base 'Perl6::Pod::Block';
  3         5  
  3         1381  
45             our $VERSION = '0.01';
46              
47             sub new {
48 0     0 0   my ( $class, %args ) = @_;
49 0           my $self = $class->SUPER::new( %args );
50 0           $self->context->{_alias}->{$self->{alias_name} } = $self->{text}->[0];
51 0           return undef;
52             }
53              
54             sub start {
55 0     0 0   my $self = shift;
56 0           my ( $parser, $attr ) = @_;
57 0           $self->delete_element->skip_content;
58 0           my @lines = split( /[\n\r]/, $self->context->custom->{_RAW_} );
59 0           my $first_line_ident;
60 0           my @res = ();
61 0           my $alias_name;
62              
63 0           foreach my $line (@lines) {
64 0 0         unless ($first_line_ident) {
65              
66             #check lengh first line
67             $line =~ m/^\s*(=alias\s+(\w+)\s+)(.*)/
68             or die 'Bad =alias at line: '
69 0 0         . $self->context->custom->{_line_num_};
70 0           $first_line_ident = length($1);
71 0           $alias_name = $2;
72              
73             #save first line
74 0           push @res, $3;
75 0           next;
76             }
77              
78             #not first line
79             $line =~ m/^\s*(=\s+)(.*)/
80             or die "Bad line in alias block "
81 0 0         . $self->context->custom->{_line_num_};
82 0           my $text = $2;
83              
84             #save ident
85 0 0         if ( length($1) > $first_line_ident ) {
86 0           $text = " " x ( length($1) - $first_line_ident ) . $text;
87             }
88 0           push @res, $text;
89             }
90              
91 0           $parser->current_context->{_alias}->{$alias_name} = join "\n", @res;
92             }
93             1;
94             __END__