NAME

Venus::Text::Tag - Text (Tag) Class

ABSTRACT

Text (Tag) Class for Perl 5

SYNOPSIS

package main;

use Venus::Text::Tag;

my $text = Venus::Text::Tag->new('t/data/sections');

# $text->find(undef, 'name');

DESCRIPTION

This package provides methods for extracting DATA sections and tag blocks from the DATA and END sections of any file or package.

DATA syntax

__DATA__

# data syntax

@@ name

Example Name

@@ end

@@ titles #1

Example Title #1

@@ end

@@ titles #2

Example Title #2

@@ end

DATA syntax (nested)

__DATA__

# data syntax (nested)

@@ nested

Example Nested

+@@ demo

blah blah blah

+@@ end

@@ end

METHODS

This package provides the following methods:

count

count(hashref $criteria) (number)

The count method uses the criteria provided to "search" for and return the number of blocks found.

Since 4.15

count example 1
# given: synopsis;

my $count = $text->count;

# 3

data

data() (string)

The data method returns the contents of the "file" to be parsed.

Since 4.15

data example 1
# given: synopsis;

$text = $text->data;

# ...

find

find(maybe[string] $list, maybe[string] $name) (arrayref)

The find method is a wrapper around "search" as shorthand for searching by list and name.

Since 4.15

find example 1
# given: synopsis;

my $find = $text->find(undef, 'name');

# [
#   { data => ["Example Name"], index => 1, list => undef, name => "name" },
# ]
find example 2
# given: synopsis;

my $find = $text->find('titles', '#1');

# [
#   { data => ["Example Title #1"], index => 2, list => "titles", name => "#1" },
# ]

new

new(any @args) (Venus::Text::Tag)

The new method constructs an instance of the package.

Since 4.15

new example 1
package main;

use Venus::Text::Tag;

my $new = Venus::Text::Tag->new;

# bless(..., "Venus::Text::Tag")
new example 2
package main;

use Venus::Text::Tag;

my $new = Venus::Text::Tag->new('t/data/sections');

# bless(..., "Venus::Text::Tag")
new example 3
package main;

use Venus::Text::Tag;

my $new = Venus::Text::Tag->new(file => 't/data/sections');

# bless(..., "Venus::Text::Tag")
find(hashref $criteria) (arrayref)

The search method returns the set of blocks matching the criteria provided. This method can return a list of values in list-context.

Since 4.15

search example 1
# given: synopsis;

my $find = $text->search({list => undef, name => 'name'});

# [
#   { data => ["Example Name"], index => 1, list => undef, name => "name" },
# ]
search example 2
# given: synopsis;

my $search = $text->search({list => 'titles', name => '#1'});

# [
#   { data => ["Example Title #1"], index => 2, list => "titles", name => "#1" },
# ]

string

string(maybe[string] $list, maybe[string] $name) (string)

The string method is a wrapper around "find" as shorthand for searching by list and name, returning only the strings found.

Since 4.15

string example 1
# given: synopsis;

my $string = $text->string(undef, 'name');

# "Example Name"
string example 2
# given: synopsis;

my $string = $text->string('titles', '#1');

# "Example Title #1"

AUTHORS

Awncorp, awncorp@cpan.org

LICENSE

Copyright (C) 2022, Awncorp, awncorp@cpan.org.

This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.