Articulate
view release on metacpan or search on metacpan
lib/Articulate/Storage/Local.pm view on Meta::CPAN
my $fn =
$self->ensure_exists( $self->true_location( $location . '/meta.yml' ) );
YAML::DumpFile( $fn, $item->meta );
}
$item->content( $self->get_content($item) );
return $item;
}
=head3 item_exists
if ($storage->item_exists( 'zone/public/article/hello-world')) {
...
}
Determines if the item has been created (only the C<meta.yml> is
tested).
=cut
sub item_exists {
my $self = shift;
my $location = shift->location;
throw_error Internal => "Bad location $location"
unless $self->navigation->valid_location($location);
return -e $self->true_location( $location . '/meta.yml' );
}
=head3 list_items
$storage->list_items ('/zone/public'); # 'hello-world', 'second-item' )
Returns a list of items in the.
=cut
sub list_items {
my $self = shift;
my $location = shift->location;
# throw_error Internal => "Bad location $location" unless $self->navigation->valid_location( $location ); # actually, no, because /zone fails but /zone/foo passes
my $true_location = $self->true_location($location);
my @contents;
return @contents unless -d $true_location;
opendir( my $dh, $true_location )
or throw_error NotFound => ( 'Could not open ' . $true_location );
while ( my $fn = readdir $dh ) {
my $child_dn = $true_location . '/' . $fn;
next unless -d $child_dn;
push @contents, $fn
if $self->navigation->valid_location( $location . '/' . $fn )
and $self->item_exists( new_location $location. '/' . $fn );
}
return @contents;
}
=head3 empty_all_content
$storage->empty_all_content;
Removes all content. This is totally irreversible, unless you took a
backup!
=cut
sub empty_all_content {
my $self = shift;
my $true_location = $self->content_base;
throw_error Internal => "Won't empty all content, this looks too dangerous"
if ( -d "$true_location/.git"
or -f "$true_location/Makefile.PL" );
File::Path::remove_tree( $self->content_base, { keep_root => 1 } );
}
=head3 delete_item
$storage->delete_item ('/zone/public');
Deletes the item and all its descendants.
=cut
sub delete_item {
my $self = shift;
my $location = shift->location;
throw_error Internal => "Use empty_all_content instead to delete the root"
if "$location" eq '/';
throw_error Internal => "Bad location $location"
unless $self->navigation->valid_location($location);
throw_error NotFound => "No content at $location"
unless $self->item_exists($location);
my $true_location = $self->true_location($location);
File::Path::remove_tree($true_location);
}
=head1 SEE ALSO
=over
=item * L<Articulate>
=item * L<Articulate::Storage::DBIC::Simple>
=back
=cut
1;
( run in 1.405 second using v1.01-cache-2.11-cpan-99c4e6809bf )