Using ref() in this is simply executing a check to whether what was passed in was a reference or not. If it is, then we can invoke as an object method and extract the package class using ref(). If not, we use the string passed in the package class.

You didn't provide the context (i.e. how this "new" is supposed to be used), neither you had posted the whole body of the function. Hence, we can only guess. From the code, I assume that this is a function intended to create a new object based on a existing one. For example, if $x is a reference to some object (likely inheriting from Room), $x->new might create a new object of the same type as $x.

Of course, this is only speculation. You need to provide more information on your case.