[code-review] CGI::Uploader

Mark Stosberg <mark-WmyhgDpj2fCHT8/[email protected]> Sun, 9 May 2004 02:42:40 +0000 (UTC)
Newsgroups gmane.comp.lang.perl.code-review-ladder
Message-ID <[email protected]>
Hello,

I'm working on a module to manage CGI uploads, specifically, meta data
is stored via DBI, and the the files are kept on the file system. 

In my experience, most web uploads seem to be images. So it seemed
reasonable and useful to me to build in some image related shortcuts. 

However, on a  recent project,I realized my architecture for the module
wouldn't generalize well for my new case. In addition to creating
thumbnails, I also needed to compress images and round the corners.

While I think some image shortcuts could be appropriate, I don't think
a function to round image corners belongs in the general API for an
file uploading system.

So I'm seeking advice on a new architecture for the system. 

You can browse docs the old (but complete) system here:
http://search.cpan.org/~markstos/CGI-Uploader-0.76_02/

Here's my idea for an improved API that I would like feedback on. 

My "big idea" is that I will remove the notion of "thumbnails" from the
API. Instead, I will replace it with a notion of "dependent" or
"generated" files. 

For images these could be thumbnails. It would also leave open the
possibility that a generated file might involve some other
transformation. It might be split up, decrypted, compressed or otherwise
transformed.

Handling these extra files is easy and convenient, because we already 
need functions for storing and retrieving the  file system and meta data
components of uploads themselves. 

I'm now thinking of designing the system in the same way that
Data::FormValidator custom constraints are handled. 

This provides a way for a user to provide a code reference and some
parameters to pass to it. The module  passes some additional arguments
to the subroutine as well. 

Generally useful transformation methods (like thumbnailing) could be
distributed in their own modules. Users could also easily define their
own. 

Here's an example of a specification with the new design. 
This would be  used in the constructor to define the names
of the files you'll be uploading, and any related generated files. 

spec   => {

           # The first image has 2 different sized thumbnails
           img_1 => {
		   		# Besides generating dependent files
				# We can also transform the file itself
				# Here, we shrink the image to be wider than 380
				transform_method => \&gen_thumb,
				params => [ w => 380 ],

		   		gen_files => { 
					'img_1_thumb_1' => {
						transform_method => \&gen_thumb,
						params => [ w => 100, h => 100 ],
					}
					'img_1_thumb_2' => {
						transform_method => \&gen_thumb,
						params => [ w => 50, h => 50 ],
					}
				}

		   },
		   
       },

############

These 'transform_method' would receive as their first two arguments
the CGI::Uploader object and a path to an input file. They would return 
a path of an output file. 

Seem reasonble? 

Thanks!

	Mark
-- 
http://mark.stosberg.com/