%# [POST PostURI] (Container)
%# Create a new object from the AtomEntry in the request's body.
%# 204: Created, but the new object has no EditURI.
%# 303: Created.  The 'Location:' header is set to the new object's EditURI
%#      (for subsequent Get/Update).
%# 400: Request failed.  Body is error message in text/plain.
%# 404: There is no container matching the specified URI.
<%INIT>
my $obj = eval {$CollectionClass->new($session{CurrentUser})->NewItem}
    or return $m->comp($ShowError, Status => 404);

my %args = $m->request_args;
$args{$1} = $2 while $Path =~ m{\G.*?(\w+)s/(\d+)/(?=\w)}g;

# XXX - factor away the creation defaults
$args{Requestor} ||= $session{CurrentUser}->Id
    if $CollectionClass->isa('RT::Tickets');

my $status = 400;

my @rv;
if ($Path =~ /.*\b(\w+)s/ and $Object and my $code = $Object->can("Add$1")) {
    @rv = $code->($Object, %args);
    $status = 200 if $rv[0];
}
else {
    @rv = $obj->Create( %args );
    if (my $id = $obj->Id) {
	$r->header_out(Location => "$BaseURI/$Path/$id");
	$status = 303;
    }
}

$r->content_type('text/plain');
$r->status($status);

print $rv[-1];
</%INIT>
<%ARGS>
$Path
$BaseURI
$Now
$ShowLink
$ShowEntry
$ShowError
$X

$Type
$Object
$CollectionClass
$FeedURI
</%ARGS>
