I think this line should be:

unless is_hash($directories) or (is_array($directories) and is_hash($directories[0])) {

to make the tests happy.