GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Data::Object::Data(3) User Contributed Perl Documentation Data::Object::Data(3)

Data::Object::Data

Podish Parser for Perl 5

  package main;

  use Data::Object::Data;

  my $data = Data::Object::Data->new(
    file => 't/Data_Object_Data.t'
  );

This package provides methods for parsing and extracting pod-like sections from any file or package. The pod-like syntax allows for using these sections anywhere in the source code and having Perl properly ignoring them.

This package supports the following scenarios:

  # POD

  # =head1 NAME
  #
  # Example #1
  #
  # =cut
  #
  # =head1 NAME
  #
  # Example #2
  #
  # =cut

  # Podish Syntax

  # =name
  #
  # Example #1
  #
  # =cut
  #
  # =name
  #
  # Example #2
  #
  # =cut

  # Podish Syntax (Nested)

  # =name
  #
  # Example #1
  #
  # +=head1 WHY?
  #
  # blah blah blah
  #
  # +=cut
  #
  # More information on the same topic as was previously mentioned in the
  # previous section demonstrating the topic as-is obvious from said section
  # ...
  #
  # =cut

  # Alternate Podish Syntax

  # @=name
  #
  # Example #1
  #
  # @=cut
  #
  # @=name
  #
  # Example #2
  #
  # @=cut

  my $data = Data::Object::Data->new(
    file => 't/examples/alternate.pod'
  );

  $data->contents('name');

  # [['Example #1'], ['Example #2']]

This package supports parsing standard POD and pod-like sections from any file or package, anywhere in the document. Additionally, this package supports an alternative POD definition syntax which helps differentiate between the traditional POD usage and other usages.

This package has the following attributes:

  data(Str)

This attribute is read-only, accepts "(Str)" values, and is optional.

  file(Str)

This attribute is read-only, accepts "(Str)" values, and is optional.

  from(Str)

This attribute is read-only, accepts "(Str)" values, and is optional.

This package implements the following methods:

  content(Str $name) : ArrayRef[Str]

The content method the pod-like section where the name matches the given string.

content example #1
  # =name
  #
  # Example #1
  #
  # =cut
  #
  # =name
  #
  # Example #2
  #
  # =cut

  my $data = Data::Object::Data->new(
    file => 't/examples/content.pod'
  );

  $data->content('name');

  # ['Example #1']
    
content example #2
  # =name
  #
  # Example #1
  #
  # +=head1 WHY?
  #
  # blah blah blah
  #
  # +=cut
  #
  # More information on the same topic as was previously mentioned in the
  # previous section demonstrating the topic as-is obvious from said section
  # ...
  #
  # =cut

  my $data = Data::Object::Data->new(
    file => 't/examples/nested.pod'
  );

  $data->content('name');

  # ['Example #1', '', '=head1 WHY?', ...]
    

  contents(Str $list, Str $name) : ArrayRef[ArrayRef]

The contents method returns all pod-like sections that start with the given string, e.g. "pod" matches "=pod foo". This method returns an arrayref of data for the matched sections. Optionally, you can filter the results by name by providing an additional argument.

contents example #1
  # =name example-1
  #
  # Example #1
  #
  # =cut
  #
  # =name example-2
  #
  # Example #2
  #
  # =cut

  my $data = Data::Object::Data->new(
    file => 't/examples/contents.pod'
  );

  $data->contents('name');

 # [['Example #1'], ['Example #2']]
    
contents example #2
  # =name example-1
  #
  # Example #1
  #
  # +=head1 WHY?
  #
  # blah blah blah
  #
  # +=cut
  #
  # ...
  #
  # =cut

  my $data = Data::Object::Data->new(
    string => join "\n\n", (
      '=name example-1',
      '',
      'Example #1',
      '',
      '+=head1 WHY?',
      '',
      'blah blah blah',
      '',
      '+=cut',
      '',
      'More information on the same topic as was previously mentioned in the',
      '',
      'previous section demonstrating the topic as-is obvious from said section',
      '',
      '...',
      '',
      '=cut'
    )
  );

  $data->contents('name');

  # [['Example #1', '', '=head1 WHY?', ...]]
    

  item(Str $name) : HashRef

The item method returns metadata for the pod-like section that matches the given string.

item example #1
  # =name
  #
  # Example #1
  #
  # =cut
  #
  # =name
  #
  # Example #2
  #
  # =cut

  my $data = Data::Object::Data->new(
    file => 't/examples/content.pod'
  );

  $data->item('name');

  # {
  #   index => 1,
  #   data => ['Example #1'],
  #   list => undef,
  #   name => 'name'
  # }
    

  list(Str $name) : ArrayRef

The list method returns metadata for each pod-like section that matches the given string.

list example #1
  # =name example-1
  #
  # Example #1
  #
  # =cut
  #
  # =name example-2
  #
  # Example #2
  #
  # =cut

  my $data = Data::Object::Data->new(
    file => 't/examples/contents.pod'
  );

  $data->list('name');

  # [{
  #   index => 1,
  #   data => ['Example #1'],
  #   list => 'name',
  #   name => 'example-1'
  # },
  # {
  #   index => 2,
  #   data => ['Example #2'],
  #   list => 'name',
  #   name => 'example-2'
  # }]
    

  list_item(Str $list, Str $item) : ArrayRef[HashRef]

The list_item method returns metadata for the pod-like sections that matches the given list name and argument.

list_item example #1
  # =name example-1
  #
  # Example #1
  #
  # =cut
  #
  # =name example-2
  #
  # Example #2
  #
  # =cut

  my $data = Data::Object::Data->new(
    file => 't/examples/contents.pod'
  );

  $data->list_item('name', 'example-2');

  # [{
  #   index => 2,
  #   data => ['Example #2'],
  #   list => 'name',
  #   name => 'example-2'
  # }]
    

  parser(Str $string) : ArrayRef

The parser method extracts pod-like sections from a given string and returns an arrayref of metadata.

parser example #1
  # given: synopsis

  $data->parser("=pod\n\nContent\n\n=cut");

  # [{
  #   index => 1,
  #   data => ['Content'],
  #   list => undef,
  #   name => 'pod'
  # }]
    

  pluck(Str $type, Str $item) : ArrayRef[HashRef]

The pluck method splices and returns metadata for the pod-like section that matches the given list or item by name. Splicing means that the parsed dataset will be reduced each time this method returns data, making this useful with iterators and reducers.

pluck example #1
  # =name example-1
  #
  # Example #1
  #
  # =cut
  #
  # =name example-2
  #
  # Example #2
  #
  # =cut

  my $data = Data::Object::Data->new(
    file => 't/examples/contents.pod'
  );

  $data->pluck('list', 'name');

  # [{
  #   index => 1,
  #   data => ['Example #1'],
  #   list => 'name',
  #   name => 'example-1'
  # },{
  #   index => 2,
  #   data => ['Example #2'],
  #   list => 'name',
  #   name => 'example-2'
  # }]
    
pluck example #2
  # =name example-1
  #
  # Example #1
  #
  # =cut
  #
  # =name example-2
  #
  # Example #2
  #
  # =cut

  my $data = Data::Object::Data->new(
    file => 't/examples/contents.pod'
  );

  $data->pluck('item', 'example-1');

  # [{
  #   index => 1,
  #   data => ['Example #1'],
  #   list => 'name',
  #   name => 'example-1'
  # }]

  $data->pluck('item', 'example-2');

  # [{
  #   index => 2,
  #   data => ['Example #2'],
  #   list => 'name',
  #   name => 'example-2'
  # }]
    
pluck example #3
  # =name example-1
  #
  # Example #1
  #
  # =cut
  #
  # =name example-2
  #
  # Example #2
  #
  # =cut

  my $data = Data::Object::Data->new(
    file => 't/examples/contents.pod'
  );

  $data->pluck('list', 'name');

  # [{
  #   index => 1,
  #   data => ['Example #1'],
  #   list => 'name',
  #   name => 'example-1'
  # },{
  #   index => 2,
  #   data => ['Example #2'],
  #   list => 'name',
  #   name => 'example-2'
  # }]

  $data->pluck('list', 'name');

  # []
    

Al Newkirk, "awncorp@cpan.org"

Copyright (C) 2011-2019, Al Newkirk, et al.

This is free software; you can redistribute it and/or modify it under the terms of the The Apache License, Version 2.0, as elucidated in the "license file" <https://github.com/iamalnewkirk/data-object-data/blob/master/LICENSE>.

Wiki <https://github.com/iamalnewkirk/data-object-data/wiki>

Project <https://github.com/iamalnewkirk/data-object-data>

Initiatives <https://github.com/iamalnewkirk/data-object-data/projects>

Milestones <https://github.com/iamalnewkirk/data-object-data/milestones>

Contributing <https://github.com/iamalnewkirk/data-object-data/blob/master/CONTRIBUTE.md>

Issues <https://github.com/iamalnewkirk/data-object-data/issues>

2020-05-31 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.