Document::Stembolt - Read & edit a document with YAML-ish meta-data


Document-Stembolt documentation Contained in the Document-Stembolt distribution.

Index


Code Index:

NAME

Top

Document::Stembolt - Read & edit a document with YAML-ish meta-data

VERSION

Top

Version 0.012

SYNOPSIS

Top

    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"

DESCRIPTION

Top

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.

AUTHOR

Top

Robert Krimen, <rkrimen at cpan.org>

BUGS

Top

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.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Document::Stembolt




You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Document-Stembolt

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Document-Stembolt

* CPAN Ratings

http://cpanratings.perl.org/d/Document-Stembolt

* Search CPAN

http://search.cpan.org/dist/Document-Stembolt

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


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