Initial troubleshooting:
- Your test.pdf has an empty Annots (annotations) array on each page.
- $page->annotation() creates a new annotation object, adds it to the page, and returns it.
- Unrelated: $page->annotation() doesn't take any arguments -- the code declares three, but never uses them. It seems to be a copy-paste error from sub resource, which immediately follows it. I've just removed them.
- If an annotations array already exists in the Page object [edit: and it's an indirect object], $page->annotation() tries to call update() on it. However, Array.pm doesn't have an update() function, and it doesn't look like it ever did.
- There are three cases of "sub update" in the codebase, and the only one that makes sense in this case is the one in Page.pm, which "marks a page to be updated". It does this by calling File.pm's out_obj with itself as the argument.
- out_obj notes that the object needs to be output when the PDF is generated (written to disk, stringified, etc.).
- Therefore, it looks like the correct code for that line is...
- $self->{'Annots'}->update();
+ $self->{' apipdf'}->out_obj($self->{'Annots'});
... because the purpose of the surrounding code seems to be "if an annotations array already exists, mark the array as having changed since we're about to add to it; otherwise, mark the page as having changed since we just added the annotations array to it."
- However, that exact line already appears just after the new annotation is created.
So, it does appear that just removing the line altogether will fix the crash without any consequences.
While writing a test for this ticket, I also discovered that the crash only happens if the array is an indirect object -- if an array already exists and it's inline, there isn't a problem.
This will be fixed in the next release, and working code is now in the repository.