NAME
PickLE::Document
- Component pick list document abstraction
SYNOPSIS
use PickLE::Document;
# Start from scratch.
my $doc = PickLE::Document->new;
$doc->add_category($category);
$doc->save("example.pkl");
# Load from file.
$doc = PickLE::Document->load("example.pkl");
# List all document properties.
$doc->foreach_property(sub {
my $property = shift;
say $property->name . ': ' . $property->value;
});
# List all components in each category.
$doc->foreach_category(sub {
my $category = shift;
$category->foreach_component(sub {
my ($component) = @_;
say $component->name;
});
});
ATTRIBUTES
- properties
-
List of all of the pick list properties in the document.
- categories
-
List of all of the categories available in the document.
METHODS
- $doc =
PickLE::Document
->new
() -
Initializes an empty document object.
- $doc =
PickLE::Document
->load
($filename) - $doc->
load
($filename) -
Parses a component pick list file located at $filename. This method can be called statically, or as an object method. In both cases a brand new object will be contructed.
- $doc =
PickLE::Document
->from_string
($str) - $doc->
from_string
($str) -
Parses a component pick list document from a string $str. This method can be called statically, or as an object method. In both cases a brand new object will be contructed.
- $doc->
add_property
(@property) -
Adds any number of proprerties in the form of PickLE::Property objects to the document.
- $doc->
add_category
(@category) -
Adds any number of categories in the form of PickLE::Category objects to the document.
- $doc->
foreach_property
($coderef) -
Executes a block of code ($coderef) for each proprety. The property object will be passed as the first argument.
- $doc->
foreach_category
($coderef) -
Executes a block of code ($coderef) for each category available in the document. The category object will be passed as the first argument.
- $property = $self->
get_property
($name) -
Gets a property of the document by its $name and returns it if found, otherwise returns
undef
. - $category = $self->
get_category
($name) -
Gets a category in the document by its $name and returns it if found, otherwise returns
undef
. - $doc->
save
($filename) -
Saves the document object to a file.
- $doc->
as_string
() -
String representation of this object, just like it is representated in the file.
PRIVATE METHODS
- $status = $self->
_parse
($fh) -
Parses the contents of a file or scalar handle ($fh) and populates the object. Returns
0
if there were parsing errors.
AUTHOR
Nathan Campos <nathan@innoveworkshop.com>
COPYRIGHT
Copyright (c) 2022- Nathan Campos.