moodle_page::set_cm currently gets a cm_info object if it is being called from a require_login function, however code manually setting a cm is going to be passing in a stdClass object from the db.
This should be tidied up and moodle_page::set_cm should really convert the stdClass object to a cm_info instance if required.
Cheers
Sam