Perl6::Pod::Parser::Utils - set of useful functions


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

Index


Code Index:

NAME

Top

Perl6::Pod::Parser::Utils - set of useful functions

SYNOPSIS

Top

    use Perl6::Pod::Parser::Utils qw(parse_URI );

DESCRIPTION

Top

Set of useful functions

METHODS

Top

parse_URI ($string)

Parse Pod's URI:.

    scheme:path#section_name(rules)

For example:

    http://www.exapmple.com/test.pod#Sect1
    test.pod
    file:bundle.pod(para :public)
    file:../file1.txt
    Name|http://www.com#test

Return stucture:

    'Name|http://example.com/index.html#txt':
      {
        'is_external' => 1,
        'name'        => 'Name',
        'section'     => 'txt',
        'address'     => 'example.com/index.html',
        'scheme'      => 'http'
      }




    '../data/test.pod':
      {
        'is_external' => '',
        'name'        => '',
        'section'     => '',
        'address'     => '../data/test.pod',
        'scheme'      => 'file'
      }







    'http://www.com/d.pod(head1 :todo, para)':
     {
          'is_external' => '1',
          'name' => '',
          'section' => '',
          'address' => 'www.com/d.pod',
          'scheme' => 'http',
          'rules' => 'head1 :todo, para'
        }

SEE ALSO

Top

http://perlcabal.org/syn/S26.html

AUTHOR

Top

Zahatski Aliaksandr, <zag@cpan.org>

COPYRIGHT AND LICENSE

Top


Perl6-Pod documentation Contained in the Perl6-Pod distribution.
package Perl6::Pod::Parser::Utils;

#$Id$

require Exporter;
*import                = \&Exporter::import;
@Perl6::Pod::Parser::Utils::EXPORT_OK = qw( parse_URI);

sub parse_URI {
    my $txt  = shift;

    #extract linkname and content
    my ( $lname, $lcontent ) = ( '', defined $txt ? $txt : '' );
    if ( $lcontent =~ /\|/ ) {
        my @all;
        ( $lname, @all ) = split( /\s*\|\s*/, $lcontent );
        $lcontent = join "", @all;
    }
    my $attr = {};

    #clean whitespaces
    $lname =~ s/^\s+//;
    $lname =~ s/\s+$//;
    $attr->{name} = $lname;
    #strip include rules ( blockname : attr, ... )
    if ( $lcontent =~  s/\s*\(
                                                                ([^\(\)]*) 
                                                          \)
                                                          \s*$//x) {
        $attr->{rules} = $1
    }
    my ( $scheme, $address, $section ) =
    # Pod::Insertion::Name or http://www.com/d.pod(head1 :todo, para)
      $lcontent =~ /\s*(\w+)\s*\:(?!\:)([^\#]*)(?:\#(.*))?/;
    #set default scheme
    unless ($scheme) {
        $scheme = 'file';
        ( $address, $section ) = $lcontent =~ /([^\#]*)(?:\#(.*))?/;
    }
    $attr->{scheme} = $scheme;
    $address = '' unless defined $address;
    $attr->{is_external} = $address =~ s/^\/\///;

    #clean whitespaces
    $address =~ s/^\s+//;
    $address =~ s/\s+$//;
    $attr->{address} = $address;

    #fix L<doc:#Special Features>
    $attr->{section} = defined $section ? $section : '';
    return $attr;
}


1;

__END__