Path::Class and translating paths

jk2addict on 2005-12-16T15:52:03

This seems like an easy thing, but it's driving me bonkers. I've been working on a photo gallery app for Catalyst. One of the 'features' I discovered last night was that when I uploaded a file on Windows to the Unix server, file($file)->basename was giving me the whole file name, not just the base name for the windows files.

Given the power of Path::Class and File::Spec, I thought surely there was a better way. But I haven't found it yet.

There is foreign_file and as_foreign, even new_foreign. They all assume that I know the source file system. When uploading files over the web, I don't.

Now sure, I could do some hackery pokery to sniff the user-agent, or sniff the filename for / or \ or : or ::, but that's bad. That's why we have the magic that is Path::Class/File::Spec to begin with.

Maybe there should be a from_foreign() that does the sniffing magic and converts the output to the native fs on which it's running?


Can you use URI::File?

jjn1056 on 2005-12-20T15:24:18

I do a lot of development across Windows and Unix boxes and have found URI::File to really help even out the path deliminator issues. However I am just learning Catalyst and am not so familiar with the classes you mentioned so I am not sure my advice will help.

BTW, Something else you should watch out for is that on UNIX the current working directory is set to the path of the script, but on windows it's set to the location to wherever perl.exe is.