Perl6::Pod::Parser::NestedAttr - handle nested attribs


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

Index


Code Index:

NAME

Top

Perl6::Pod::Parser::NestedAttr - handle nested attribs

SYNOPSIS

Top

    =begin para
        We are all of us in the gutter,E<NL>
        but some of us are looking at the stars!
    =end para
    =begin para :nested(2)
            -- Oscar Wilde
    =end para

DESCRIPTION Any block can be nested by specifying a :nested option on it:

Top

    =begin para :nested
        We are all of us in the gutter,E<NL>
        but some of us are looking at the stars!
    =end para

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.
#===============================================================================
#
#  DESCRIPTION:  Do :nested(1) attr
#
#       AUTHOR:  Aliaksandr P. Zahatski, <zahatski@gmail.com>
#===============================================================================
#$Id$
package Perl6::Pod::Parser::NestedAttr;
use strict;
use warnings;
use Data::Dumper;
use Test::More;
use base 'Perl6::Pod::Parser';

sub on_start_element {
    my $self = shift;
    my $el   = shift;
    my $attr = $el->get_attr;
    my @res  = ($el);
    if ( my $nested = $attr->{nested} ) {

        #get level
        ($nested) = @{ ref($nested) ? $nested : [$nested] };

        #wrap contents to format codes
        unshift @res, $self->mk_start_element( $el->mk_block('blockquote') )
          for ( 1 .. $nested );
    }
    return \@res;
}

sub on_end_element {
    my $self = shift;
    my $el   = shift;
    my $attr = $el->get_attr;
    my @res  = ($el);
    if ( my $nested = $attr->{nested} ) {

        #get level
        ($nested) = @{ ref($nested) ? $nested : [$nested] };

        #wrap contents to format codes
        push @res, $self->mk_end_element( $el->mk_block('blockquote') )
          for ( 1 .. $nested );
    }
    return \@res;
}
1;
__END__