| 1 | package Giddy::Role::DocumentStorer; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use Any::Moose 'Role'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use YAML::XS; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 2 | our $VERSION = "0.013_001"; | |||||||||
| 10 | 2 | $VERSION = eval $VERSION; | |||||||||
| 11 | |||||||||||
| 12 | 2 | requires 'db'; | |||||||||
| 13 | 2 | requires '_path_to'; | |||||||||
| 14 | |||||||||||
| 15 | =head1 NAME | ||||||||||
| 16 | |||||||||||
| 17 | Giddy::Role::DocumentStorer - Provides document storing for Giddy::Collection | ||||||||||
| 18 | |||||||||||
| 19 | =head1 VERSION | ||||||||||
| 20 | |||||||||||
| 21 | version 0.013_001 | ||||||||||
| 22 | |||||||||||
| 23 | =head1 SYNOPSIS | ||||||||||
| 24 | |||||||||||
| 25 | # used internally | ||||||||||
| 26 | |||||||||||
| 27 | =head1 DESCRIPTION | ||||||||||
| 28 | |||||||||||
| 29 | This role provides document storing capabilities to L<Giddy::Collection> and L<Giddy::Collection::InMemory>. | ||||||||||
| 30 | |||||||||||
| 31 | Requires the attributes 'db' and '_path_to' to be implemented by consuming classes. | ||||||||||
| 32 | |||||||||||
| 33 | =head1 METHODS | ||||||||||
| 34 | |||||||||||
| 35 | =head2 _store_document( $filename, \%attributes ) | ||||||||||
| 36 | |||||||||||
| 37 | =cut | ||||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | sub _store_document { | ||||||||
|
Subroutine
_store_document: not called CC=5 SCAR=34.0
| |||||||||||
| 40 | 0 | my ($self, $filename, $attrs) = @_; | |||||||||
| 41 | |||||||||||
| 42 | # don't allow the _name attribute | ||||||||||
| 43 | 0 | delete $attrs->{_name}; | |||||||||
| 44 | |||||||||||
| 45 | 0 | my $fpath = $self->_path_to($filename); | |||||||||
| 46 | 0 | ▶ | if (exists $attrs->{_body}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | my $body = delete $attrs->{_body}; | |||||||||
| 48 | |||||||||||
| 49 | 0 | my $content = ''; | |||||||||
| 50 | 0 | ▶ | $content .= Dump($attrs) . "\n" if scalar keys %$attrs; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 0 | ▶ | $content .= $body if $body; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 0 | ▶ | $content = ' ' unless $content; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 0 | $content =~ s/^---\n//; | |||||||||
| 54 | |||||||||||
| 55 | # create the document | ||||||||||
| 56 | 0 | $self->db->_create_file($fpath, $content, 0664); | |||||||||
| 57 | } else { | ||||||||||
| 58 | # create the document directory | ||||||||||
| 59 | 0 | $self->db->_create_dir($fpath); | |||||||||
| 60 | |||||||||||
| 61 | # create the attributes file | ||||||||||
| 62 | 0 | my $yaml = Dump($attrs); | |||||||||
| 63 | 0 | $yaml =~ s/^---\n//; | |||||||||
| 64 | 0 | $self->db->_create_file($fpath.'/attributes.yaml', $yaml, 0664); | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | # stage the document | ||||||||||
| 68 | 0 | $self->db->stage($fpath); | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | =head1 AUTHOR | ||||||||||
| 72 | |||||||||||
| 73 | Ido Perlmuter, C<< <ido at ido50.net> >> | ||||||||||
| 74 | |||||||||||
| 75 | =head1 BUGS | ||||||||||
| 76 | |||||||||||
| 77 | Please report any bugs or feature requests to C<bug-giddy at rt.cpan.org>, or through | ||||||||||
| 78 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Giddy>. I will be notified, and then you'll | ||||||||||
| 79 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 80 | |||||||||||
| 81 | =head1 SUPPORT | ||||||||||
| 82 | |||||||||||
| 83 | You can find documentation for this module with the perldoc command. | ||||||||||
| 84 | |||||||||||
| 85 | perldoc Giddy::Role::DocumentStorer | ||||||||||
| 86 | |||||||||||
| 87 | You can also look for information at: | ||||||||||
| 88 | |||||||||||
| 89 | =over 4 | ||||||||||
| 90 | |||||||||||
| 91 | =item * RT: CPAN's request tracker | ||||||||||
| 92 | |||||||||||
| 93 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Giddy> | ||||||||||
| 94 | |||||||||||
| 95 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 96 | |||||||||||
| 97 | L<http://annocpan.org/dist/Giddy> | ||||||||||
| 98 | |||||||||||
| 99 | =item * CPAN Ratings | ||||||||||
| 100 | |||||||||||
| 101 | L<http://cpanratings.perl.org/d/Giddy> | ||||||||||
| 102 | |||||||||||
| 103 | =item * Search CPAN | ||||||||||
| 104 | |||||||||||
| 105 | L<http://search.cpan.org/dist/Giddy/> | ||||||||||
| 106 | |||||||||||
| 107 | =back | ||||||||||
| 108 | |||||||||||
| 109 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 110 | |||||||||||
| 111 | Copyright 2011 Ido Perlmuter. | ||||||||||
| 112 | |||||||||||
| 113 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 114 | under the terms of either: the GNU General Public License as published | ||||||||||
| 115 | by the Free Software Foundation; or the Artistic License. | ||||||||||
| 116 | |||||||||||
| 117 | See http://dev.perl.org/licenses/ for more information. | ||||||||||
| 118 | |||||||||||
| 119 | =cut | ||||||||||
| 120 | |||||||||||
| 121 | 2 | 1; | |||||||||