Articulate

 view release on metacpan or  search on metacpan

lib/Articulate/Storage/DBIC/Simple.pm  view on Meta::CPAN


sub create_item {
  my $self     = shift;
  my $item     = shift;
  my $location = $item->location;
  throw_error Internal => "Bad location " . $location
    unless $self->navigation->valid_location($location);
  throw_error AlreadyExists => "Cannot create: item already exists at "
    . $location
    if $self->item_exists($location);
  my $dbic_item = $self->real_to_dbic($item);
  $dbic_item->insert();
  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);
  !!$self->dbic_find($location);
}

=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 $item        = shift;
  my $location    = $item->location;
  my $qm_location = $item->location;
  my $dbic_items  = $self->schema->resultset('Articulate::Item')
    ->search( { location => { like => $qm_location . '%' } } );
  my $location_specification = new_location_specification( $location . '/*' );
  return map { $_->[-1] }
    grep     { $location_specification->matches($_); }
    map      { new_location( $_->location ) } $dbic_items->all;
}

=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;
  $self->schema->resultset('Articulate::Item')->delete();
}

=head3 delete_item

  $storage->delete_item ('/zone/public');

Deletes the item and all its descendants.

=cut

sub delete_item {
  my $self        = shift;
  my $item        = shift;
  my $qm_location = $item->location;
  my $dbic_items  = $self->schema->resultset('Articulate::Item')
    ->search( { location => { like => "$qm_location\%" } } );

  # todo: fix case of "foo" matches "foobar"
  $dbic_items->count
    or throw_error NotFound => 'Item does not exist at ' . $item->location;
  $dbic_items->delete();
}

=head1 SEE ALSO

=over

=item * L<Articulate>

=item * L<DBI>

=item * L<DBIx::Class>

=item * L<Articulate::Storage::Local>

=item * L<Articulate::Storage::DBIC::Simple::Schema>

=back

=cut

1;



( run in 3.312 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )