Skip Menu |

This queue is for tickets about the File-BaseDir CPAN distribution.

Report information
The Basics
Id: 30138
Status: resolved
Priority: 0/
Queue: File-BaseDir

People
Owner: pardus [...] cpan.org
Requestors: matisse [...] spamcop.net
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: 0.03



Subject: Proposed new version: adds xdg_config_resource() and xdg_data_resource()
The attached tarball contains a proposed new version '0.021' built from 0.02. This proposed version adds two new functions: xdg_config_resource() and xdg_data_resource() which find both files and directories (instead of only finding files.)
Subject: File-BaseDir-0.021.tar.gz
Download File-BaseDir-0.021.tar.gz
application/x-gzip 3.5k

Message body not shown because it is not plain text.

How about wrapping that functionality into the *_dirs functions ? At the moment these functions do not take any arguments anyway. The word "resource" seems non-intuitive to me. Only issue is that semantics will change a bit because the dirs functions will also need to check the home directory. Another option might be to give the *_files functions a switch to look for directories instead of files. Would "xdg_data_files('-d', 'foo')" become to ugly ?
From: matisse [...] spamcop.net
The "resource" name was borrowed from Java's java.lang.Class.getResource() See http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassLoader.html#getResource(java.lang.String) or http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassLoader.html#getResourceAsStream(java.lang.String) If adding arguments to *_files seems better to you then I would consider allowing the extra argument to contain any of the file test operators, and the default would be '-f', or perhaps allow passing a coderef?
I have problems with the proposed solutions. (Sorry to butt in, I was working on another File::BaseDir ticket) There's really two ideas here. The first is to smash together file and directory searching. Files and directories are generally treated as different things in your code. It's unlikely that you want to do the same thing with a file and a directory, especially a data directory vs a data file. Thus having one function to search for both seems odd. The proposed solutions to this complicate the interface. "resource" is a terribly generic term and doesn't really suggest "file or directory" but "anything". Maybe a database, a socket, a display device? It also leads to ambiguities, did you mean to search for a file or a directory? No way to tell. So that's right out. By making xdg_data_files() search for directories, or vice versa, is also bad. It means the name lies. "xdg_data_files" is going to have you data files, not directories. The proper name for this function would be "xdg_data_files_and_directories". A contraction in a function name is a screaming red flag that the function is trying to do much. This complicates the code, documentation and user understanding of the function. For the ultimate example of this, see the "find" program. But smashing the file and directory functionality together doesn't seem to be the real user desire. It's not actually a problem but an attempted solution at the real problem... The real user desire here is to have xdg_data_dirs() search for a directory under it's data dirs, and that seems valid enough. You can add an argument to xdg_data_dirs() and all is well. The function names still reflect what they do, there's no smashing together of disparate functionality, no special flags to pass in. Even better, the two functions now work more like each other than before.
On Mon Oct 22 13:45:44 2007, MSCHWERN wrote: Show quoted text
> The real user desire here is to have xdg_data_dirs() search for a > directory under it's data dirs, and that seems valid enough. You can > add an argument to xdg_data_dirs() and all is well
If we do likewise for xdg_config_dirs() then that would work for me. If that's generally acceptable I'll rework my proposed version to do that. So if you pass an argument to either xdg_data_dirs() or xdg_config_dirs() then the argument is interpreted as a relative path and you get back a full path if a (readable ?) match is found or false if nothing is found.
On Mon Oct 22 14:42:17 2007, MATISSE wrote: Show quoted text
> If we do likewise for xdg_config_dirs() then that would work for me. If > that's generally acceptable I'll rework my proposed version to do that.
I'm working on it already, will upload a new version in a couple of days.
On Mon Oct 22 14:58:54 2007, PARDUS wrote: Show quoted text
> I'm working on it already, will upload a new version in a couple of days.
Cool. Please steal my (improved) unit tests!
Uploaded 0.03 yesterday. Will close this ticket as soon as RT syncs the new version number.