Ported chained_path() to XS