in reply to $class name not pass in the new()

If you "use warnings;" in the package, you get these helpful messages:
Use of uninitialized value $class in concatenation (.) or string at An +imal.pl line 7. Cow goes moooo! Use of uninitialized value $class in concatenation (.) or string at An +imal.pl line 13. Horse goes neigh! Use of uninitialized value $class in concatenation (.) or string at An +imal.pl line 19. Sheep goes baaaah!
for the stuff you say is "Non working code".

This gives a clear hint on what $class is set to when invoked that way, and why it "does not work".

             All great truths begin as blasphemies.
                   ― George Bernard Shaw, writer, Nobel laureate (1856-1950)