Author image Zahatski Aliaksandr
and 1 contributors


Perl6::Pod::Parser::AddIds - generate attribute id for elements


       #make filter with namespace for generated id
       my $add_ids_ns =  new Perl6::Pod::Parser::AddIds:: 
       my $add_ids_ns_file =  new Perl6::Pod::Parser::AddIds:: 
       #leave empty namespace
       my $add_ids =  new Perl6::Pod::Parser::AddIds::;
       my $out = '';
       my $to_mem = new Perl6::Pod::To::XML:: out_put => \$out;
       #make pipe for process pod
       my $p = create_pipe( 'Perl6::Pod::Parser', $add_ids_ns , $to_mem);
       $p->parse( \$pod_text );
       print $out 


Perl6::Pod::Parser::AddIds - add id attribute to processed pods elements.

     my $add_ids = new Perl6::Pod::Parser::AddIds:: ns=>"namespace";

For Pod:

        =begin pod
        =head1 test
        =end pod

XML is:

    <pod pod:type='block'
      <head1 pod:type='block' pod:id='namespace:test_tst2'>test

Added atribute pod:id :


_make_id($text[, $base_id])

Function will construct an element id string. Id string is composed of join (':', $base_id || $parser->{base_id} , $text), where $text in most cases is the pod heading text.

The xml id string has strict format. Checkout "cleanup_id" function for specification.


Calls $parser->make_id($text) and checks if such id was already generated. If so, generates new one by adding _i1 (or _i2, i3, ...) to the id string. Return value is new uniq id string.


This function is used internally to remove/change any illegal characters from the elements id string. (see for the id string specification)

    $id_string =~ s/<!\[CDATA\[(.+?)\]\]>/$1/g;   # keep just inside of CDATA
    $id_string =~ s/<.+?>//g;                     # remove tags
    $id_string =~ s/^\s*//;                       # ltrim spaces
    $id_string =~ s/\s*$//;                       # rtrim spaces
    $id_string =~ tr{/ }{._};                     # replace / with . and spaces with _
    $id_string =~ s/[^\-_a-zA-Z0-9\.: ]//g;       # closed set of characters allowed in id string

In the worst case when the $id_string after clean up will not conform with the specification, warning will be printed out and random number with leading colon will be used.