| Document-Stembolt documentation | Contained in the Document-Stembolt distribution. |
Document::Stembolt - Read & edit a document with YAML-ish meta-data
Version 0.012
my $content;
$content = Document::Stembolt::Content->read_string(<<_END_);
# vim: #
---
hello: world
---
This is the body
_END_
$content->preamble "# vim: #\n"
$content->header { hello => world }
$content->body "This is the body\n"
This distribution is meant to take the headache out of reading, writing, and editing "interesting" documents. That is, documents with both content and meta-data (via YAML::Tiny)
More documentation coming soon, check out the code and tests for usage and examples. This is pretty beta, so the interface might change.
Robert Krimen, <rkrimen at cpan.org>
Please report any bugs or feature requests to bug-document-stembolt at rt.cpan.org, or through
the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Document-Stembolt. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc Document::Stembolt
You can also look for information at:
Copyright 2008 Robert Krimen, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Document-Stembolt documentation | Contained in the Document-Stembolt distribution. |
package Document::Stembolt; use warnings; use strict;
our $VERSION = '0.012';
use Moose; use Document::Stembolt::Content; use MooseX::Types::Path::Class qw/Dir File/; has content => qw/is ro lazy_build 1 isa Document::Stembolt::Content/, handles => [qw/preamble header body/]; sub _build_content { my $self = shift; return Document::Stembolt::Content->new; } has file => qw/is ro coerce 1 required 1/, isa => File; sub BUILD { my $self = shift; $self->read if -e $self->file; } sub read { my $self = shift; $self->content->read($self->file); } sub write { my $self = shift; $self->content->write($self->file); } sub _editor { return [ split m/\s+/, ($ENV{VISUAL} || $ENV{EDITOR}) ]; } sub _edit_file { my $file = shift; die "Don't know what editor" unless my $editor = _editor; my $rc = system @$editor, $file; unless ($rc == 0) { my ($exit_value, $signal, $core_dump); $exit_value = $? >> 8; $signal = $? & 127; $core_dump = $? & 128; die "Error during edit (@$editor): exit value ($exit_value), signal ($signal), core_dump($core_dump): $!"; } } sub edit { my $self = shift; $self->write; _edit_file $self->file; $self->read; }
1; # End of Document::Stembolt