(PUP-2568) Downcase class name before validating

Previously the check for a valid name was done against the raw input,
however it later downcased the name and used that form. This order
caused Class['A'] to be an error, which isn't desired (at least not
until PUP-1810 is taken care of). By just changing the order of
operations capital letters are once again allowed.
(maint) Reorder code to increase clarity

There were a lot of unless cases that made it hard for me to track down
the path of what was actually accepted. This inverts the branches so
that the if statements lay out what is required for the good case and
the else clauses express the various failures.

In addition there were a few error scenarios where reordering was
possible and reduced the amount of work that needed to be done before
the error was detected.
(PUP-2568) Remove unnecessary calls

There are several calls that can be removed from various paths. Downcase
isn't needed for the PResourceType's type_name, since that is already
downcased (removes a string copy). The other change is that the NAME
pattern can handle leading :: and so that only needs to be stripped off
if it is a valid name (removes a string copy).
Merge branch 'pr/2656' into stable

* pr/2656:
  (PUP-2568) Remove unnecessary calls
  (maint) Reorder code to increase clarity
  (PUP-2568) Downcase class name before validating

Closes GH-2656