|
PostScript::CDCover - a simple module that generates CD covers in Postscript |
PostScript::CDCover - a simple module that generates CD covers in Postscript
use PostScript::CDCover;
my $cd = new PostScript::CDCover -root => 'root', -title => 'Backup';
$cd->add_file('root/sub1/file11');
$cd->add_file('root/sub1/file12');
$cd->add_file('root/sub2/file21');
$cd->add_file('root/sub2/file22');
$cd->flush();
This class generates a Postscript program that prints a CD cover suitable for a CD jewel case. A directory tree is printed on the cover in columns, first on the front page, then on the inner page (the one that is visible when the box is open), and finally on the back label. All in all, the output consists of two A4 pages, one for the front and inner pages, and one for the back label. People using exotic paper formats should still be able to print, provided that their paper size is close enough to A4, as the labels are drawn rather far from the paper edge. Notably, printing on Letter has been reported to not cause any trouble.
A title is printed on top of the front page, and on the sides of the back label. Various attributes alter the behaviour of the module and the layout of the generated cover.
Typically, a program using this module should:
add_directory() and add_file() methods.
flush() method to actually generate the Postscript program.
Such a program (too usable actually to be called a mere example) is shipped
with this module: pscdcover(1)
The output generated by the flush() method can be directly printed or converted
to PDF or whatever. However, it has been designed to be easily modified, even
without much knowledge of the Postscript language.
The layout of the file and directory names in the different columns and pages is done by the PostScript program. This makes it possible and easy to edit the resulting PostScript program with a text editor and remove some lines.
The editable section looks like this (text within parentheses are the files and directory names, the figure that follows it is the depth in the directory tree):
(directory 1) 0 folder_title
(file 1) 1 file_title
(file 2) 1 file_title
(file 3) 1 file_title
(file 4) 1 file_title
(file 5) 1 file_title
(file 6) 1 file_title
(file 7) 1 file_title
(file 8) 1 file_title
(file 9) 1 file_title
(file 10) 1 file_title
(file 11) 1 file_title
(file 12) 1 file_title
(directory 2) 0 folder_title
In order to shorten the list (so that it fits on the three pages, for instance), you may simply change the above to:
(directory 1) 0 folder_title
(...) 1 file_title
(lots of files) 1 file_title
(...) 1 file_title
(directory 2) 0 folder_title
You need not worry about the final layout, whether a directory has changed columns or not, all this is taken care of by the PostScript interpreter.
new() creates and returns an instance of PostScript::CDCover. new() accepts as
arguments a list of key/value pairs to initialize attributes. Each value is
simply passed to the method named after the key. The key may optionally be
prefixed with a dash, and of course, the use of double-barrel arrows =>
is recommended for readability.
These two code snippets are equivalent:
my $cd = new PostScript::CDCover;
$cd->all(1);
$cd->box(1);
$cd->files(0);
my $cd = new PostScript::CDCover -all => 1, -box => 1, -files => 0;
Attributes are accessed through accessor methods. These methods, when called without aN ARGUMENt, will return the attribute's value. With an argument, they will set the attribute's value to that argument, and return the former value.
When applicable, the default value is given in parentheses.
cdcolor and foldercolor attributes.
columns set to
0.
\*STDOUT, meaning
the standard output), a reference to a scalar to which the output is appended,
a reference to a subroutine which is called, passing the output as a parameter,
or any object reference which implements a print() method (e.g. IO::Handle)
which will be called, passing the generated output as a parameter.
add_directory() or add_file(), so that the
CD-ROM mount point does not show on the CD cover.
add_directory() and add_file() will
call add_directory() for any parent directory along the way. Calling
add_directory() is still useful for empty directories, non empty ones would be
created when adding files within.
flush() can called repeatedly, changing a couple of attributes in between, e.g.:
$cd->color(1);
$cd->flush();
$cd->color(0);
$cd->flush();
Very likely.
pscdcover(1)
Copyright © 2004
Cédric Bouvier <cbouvi@cpan.org>
Thank you to Terry Gliedt, Sean the RIMBoy, Michael M. Tung for their help with bug fixing and enhancing, and to Andy Wardley (of Template Toolkit fame) whom I borrowed the versatile output destination code from.
|
PostScript::CDCover - a simple module that generates CD covers in Postscript |