Custom scrips: diff between prep and cleanup?

I’m looking at writing a custom scrip (to search the text of the message
for a key word and set the priority accordingly). I’m finding that
there isn’t a lot of info about how to do this, but did find a message
that had an example:

So now I understand (from this and other bits I’ve found) that the
custom condition and action are Perl code, but I’m not sure what the
difference is between the cleanup section and the preparation secion of
the action are. What’s more confusing is that looking at the files in
/opt/rt3/lib/RT/Action, I noticed that the actions are broken up into
prepare and commit instead of prepare and cleanup (which seems to make
more sense, actually, kind of sort of anyway).

Also, there doesn’t seem to be a one to one correspondence between the
scrips and the Actions directory … For example, there’s a file called that I could probably borrow code from, but I’m curious
why it’s not in the drop down so I wouldn’t need to borrow code. It
just returns 1 for the preparation section, so it’s not shedding a lot
of light …

Any hints?

Also, what exactly is $self in this context? I thought it was the
current Transaction object, but now I’m thinking it’s a ScripAction