
String::Sections - Extract labelled groups of sub-strings from a string.

version 0.1.1

use String::Sections;
my $sections = String::Sections->new();
$sections->load_list( @lines );
# TODO
# $sections->load_string( $string );
# $sections->load_filehandle( $fh );
#
# $sections->merge( $other_sections_object );
my @section_names = $sections->section_names();
if ( $sections->has_section( 'section_label' ) ) {
my $string_ref = $sections->section( 'section_label' );
...
}

Data Section sports the following default data markup
__[ somename ]__ Data __[ anothername ]__ More data
This module is designed to behave as a work-alike, except on already extracted string data.

my $object = String::Sections->new(); my $object = String::Sections->new( attribute_name => 'value' );
my @strings = <$fh>; $object->load_list( @strings ); $object->load_list( \@strings );
This method handles data as if it had been slopped in unchomped from a filehandle.
Ideally, each entry in @strings will be terminated with $/ , as the collated data from each section is concatenated into a large singular string, e.g.:
$object->load_list("__[ Foo ]__\n", "bar\n", "baz\n" );
$object->section('Foo')
# bar
# baz
$object->load_list("__[ Foo ]__\n", "bar", "baz" );
$object->section('Foo');
# barbaz
$object->load_list("__[ Foo ]__", "bar", "baz" ) # will not work by default.
This behaviour may change in the future, but this is how it is with the least effort for now.
TODO
$object->load_filehandle( $fh )
TODO
my @names = $object->section_names;
Returns a list of the sections that have been extracted so far.
if( $object->has_section('Foo') ){
# code
}
Determines if the given section name has been extracted.
my $str = $object->section('Foo');
print ${ $str };
This returns a REFERENCE to a String that was parsed from section "Foo".

This code is still new and under development.
All the below facets are likely to change at some point, but don't largely contribute to the API or usage of this module.
To make some of the development features easier.

This modules primary inspiration is Data::Section, but intending to split and decouple many of the internal parts to add leverage to the various behaviors it contains.
Data::Handle solves part of a problem with Perl by providing a more reliable interface to the __DATA__ section in a file that is not impeded by various things that occur if its attempted to be read more than once.
In future, I plan on this being the syntax for connecting Data::Handle with this module to emulate Data::Section:
my $dh = Data::Handle->new( __PACKAGE__ ); my $ss = String::Sections->new( stop_at_end => 1 ); $ss->load_filehandle( $dh );
This doesn't implicitly perform any of the inheritance tree magic Data::Section does, but its also planned on making that easy to do when you want it with ->merge( $section )
For now, the recommended code is not so different:
my $dh = Data::Handle->new( __PACKAGE__ ); my $ss = String::Sections->new( stop_at_end => 1 ); $ss->load_list( <$dh> );
Its just somewhat less efficient.

Kent Fredric <kentnl@cpan.org>

This software is copyright (c) 2011 by Kent Fredric <kentnl@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.