NAME

Data::Object::Data

ABSTRACT

Data-Object Data Extraction Class

SYNOPSIS

use Data::Object::Data;

my $data = Data::Object::Data->new;

This example is extracting from the main package.

use Data::Object::Data;

my $data = Data::Object::Data->new(from => 'Example::Package');

This example is extracting from a class.

use Data::Object::Data;

my $data = Data::Object::Data->new(file => 'lib/Example/Package.pm');

This example is extracting from a file.

use Data::Object::Data;

my $data = Data::Object::Data->new(data => [,'...']);

This example is extracting from existing data.

package Command;

use Data::Object::Data;

=pod help

fetches results from the api

=cut

my $data = Data::Object::Data->new(
  from => 'Command'
);

my $help = $data->content('help');
# fetches results ...

my $token = $data->content('token');
# token: the access token ...

my $secret = $data->content('secret');
# secret: the secret for ...

my $flags = $data->contents('flag');
# [,...]

__DATA__

=flag secret

secret: the secret for the account

=flag token

token: the access token for the account

=cut

DESCRIPTION

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

INHERITANCE

This package inherits behaviors from:

Data::Object::Base

LIBRARIES

This package uses type constraints defined by:

Data::Object::Library

METHODS

This package implements the following methods.

content

content(Str $arg1) : Str

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

content example
=pod help

Example content

=cut

# given $data

$data->content('help');

# Example content

contents

contents(Str $arg1, Str $arg2) : 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
=pod help

Example content

=cut

# given $data

$data->contents('pod');

# [,...]

$data->contents('pod' , 'help');

# [,...]

data

data(Str $arg1) : ArrayRef

The data method returns the contents from the DATA and END sections of a package.

data example
# given $data

$data->data($class);

# ...

file

file(Str $arg1) : ArrayRef

The file method returns the contents of a file which contains pod-like sections for a given filename.

file example
# given $data

$data->file($args);

# ...

from_data

from_data(Str $arg1) : Str

The from_data method returns content for the given class to be passed to the constructor. This method isn't meant to be called directly.

from_data example
# given $data

$data->from_data($class);

# ...

from_file

from_file(Str $arg1) : Str

The from_data method returns content for the given file to be passed to the constructor. This method isn't meant to be called directly.

from_file example
# given $data

$data->from_file($file);

# ...

item

item(Str $arg1) : HashRef

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

item example
=pod help

Example content

=cut

# given $data

$data->item('help');

# {,...}

list

list(Str $arg1) : ArrayRef

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

list example
=pod help

Example content

=cut

# given $data

$data->list('pod');

# [,...]

list_item

list_item(Str $arg1, Str $arg2) : ArrayRef[ArrayRef]

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

list_item example
=pod attribute

Attribute #1 content

=cut

=pod attribute

Attribute #2 content

=cut

# given $data

$data->list_item('pod', 'attribute');

# [,...]

parser

parser(Str $arg1) : ArrayRef

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

parser example
# given $data

$data->parser($string);

# [,...]

pluck

pluck(Str $arg1, Str $arg2) : HashRef

The pluck method splices and returns metadata for the pod-like section that matches the given list or item by name.

pluck example
=pod help

Example content

=cut

# given $data

$data->pluck('item', 'help');

# {,...}

CREDITS

Al Newkirk, +319

Anthony Brummett, +10

Adam Hopkins, +2

José Joaquín Atria, +1

AUTHOR

Al Newkirk, awncorp@cpan.org

LICENSE

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 here, https://github.com/iamalnewkirk/do/blob/master/LICENSE.

PROJECT

Wiki

Project

Initiatives

Milestones

Contributing

Issues

SEE ALSO

To get the most out of this distribution, consider reading the following:

Do

Data::Object

Data::Object::Class

Data::Object::ClassHas

Data::Object::Role

Data::Object::RoleHas

Data::Object::Library