Catalyst-Controller-Atompub

 view release on metacpan or  search on metacpan

samples/MyAtom/lib/MyAtom/Controller/MyCollection.pm  view on Meta::CPAN

    # Retrieve Entries sorted in descending order
    my $rs = $c->model('DBIC::Entries')->search({}, {
        order_by => 'edited desc',
    });

    # Add Entries to the Feed
    while (my $entry_resource = $rs->next) {
        my $entry = XML::Atom::Entry->new(\$entry_resource->xml);
        $feed->add_entry($entry);
    }

    # Return true on success
    1;
}

# Create new Entry in the method with "Atompub(create)" attribute
sub create_entry :Atompub(create) {
    my($self, $c) = @_;

    # URI of the new Entry, which was determined by C::C::Atompub
    my $uri = $self->entry_resource->uri;

    # app:edited element, which was assigned by C::C::Atompub,
    # is coverted into UNIX time
    my $edited = $self->edited->epoch;

    # POSTed Entry (XML::Atom::Entry)
    my $entry = $self->entry_resource->body;

    # Create new Entry
    $c->model('DBIC::Entries')->create({
        uri    => $uri,
        edited => $edited,
        xml    => $entry->as_xml,
    });

    # Return true on success
    1;
}

# Search the requested Entry in the method with "Atompub(read)"
# attribute
sub get_entry :Atompub(read) {
    my($self, $c) = @_;

    my $uri = $c->req->uri;

    # Retrieve the Entry
    my $rs = $c->model('DBIC::Entries')->find({ uri => $uri });

    # Set the Entry
    my $entry = XML::Atom::Entry->new(\$rs->xml);
    $self->entry_resource->body($entry);

    # Return true on success
    1;
}

# Update the requested Entry in the method with "Atompub(update)"
# attribute
sub update_entry :Atompub(update) {
    my($self, $c) = @_;

    my $uri = $c->req->uri;

    # app:edited element, which was assigned by C::C::Atompub,
    # is coverted into UNIX time
    my $edited = $self->edited->epoch;

    # PUTted Entry (XML::Atom::Entry)
    my $entry = $self->entry_resource->body;

    # Update the Entry
    $c->model('DBIC::Entries')->find({ uri => $uri })->update({
        uri => $uri,
        edited => $edited,
        xml => $entry->as_xml,
    });

    # Return true on success
    1;
}

# Delete the requested Entry in the method with "Atompub(delete)"
# attribute
sub delete_entry :Atompub(delete) {
    my($self, $c) = @_;

    my $uri = $c->req->uri;

    # Delete the Entry
    $c->model('DBIC::Entries')->find({ uri => $uri })->delete;

    # Return true on success
    1;
}

1;



( run in 0.827 second using v1.01-cache-2.11-cpan-39bf76dae61 )