EBook-Tools
view release on metacpan or search on metacpan
lib/EBook/Tools.pm view on Meta::CPAN
debug(3,"DEBUG[",$subname,"]");
my $dir;
if(-d $ENV{HOME}) {
$dir = $ENV{HOME} . '/.ebooktools';
}
if($OSNAME eq 'MSWin32') {
if(not -d $dir and -d $ENV{USERPROFILE}) {
$dir = $ENV{USERPROFILE} . '\Application Data\EBook-Tools';
}
}
if($dir) {
if(! -d $dir) {
mkpath($dir)
or croak($subname,
"(): unable to create configuration directory '",
$dir,"'!\n");
}
return $dir;
}
else { return; }
}
=head2 C<ymd_validate($year,$month,$day)>
Make sure month and day have valid values. Return the passed values
if they are, return 3 undefs if not. Testing of month or day can be
skipped by passing undef in that spot.
=cut
sub ymd_validate {
my ($year,$month,$day) = @_;
return (undef,undef,undef) unless($year);
if($month) {
return (undef,undef,undef) if($month > 12);
if($day) {
if(!eval { timelocal(0,0,0,$day,$month-1,$year); }) {
debug(1,"DEBUG: timelocal validation failed for year=",
$year," month=",$month," day=",$day);
return (undef,undef,undef);
}
}
return ($year,$month,$day);
}
# We don't have a month. If we *do* have a day, the result is
# broken, so send back the undefs.
return (undef,undef,undef) if($day);
return ($year,undef,undef);
}
########## END CODE ##########
=head1 BUGS AND LIMITATIONS
=over
=item * fix_links() could be improved to download remote URIs instead
of ignoring them.
=item * fix_links() needs to check the <reference> links under <guide>
=item * fix_links() needs to be redone with HTML::TreeBuilder or
Mojo::DOM to avoid the weakness with newlines between attribute names
and values
=item * Need to implement fix_tours() that should collect the related
elements and delete the parent if none are found. Empty <tours>
elements aren't allowed.
=item * fix_languages() needs to convert language names into IANA
language codes.
=item * set_language() should add a warning if the text isn't a valid
IANA language code.
=item * NCX generation only generates from the spine. It should be
possible to use a TOC html file for generation instead. In the long
term, it should be possible to generate one from the headers and
anchors in arbitrary HTML files.
=item * It might be better to use sysread / index / substr / syswrite in
&split_metadata to handle the split in 10k chunks, to avoid massive
memory usage on large files.
This may not be worth the effort, since the average size for most
books is less than 500k, and the largest books are rarely over 10M.
=item * The only generator is currently for .epub books. PDF,
PalmDoc, Mobipocket, Plucker, and iSiloX are eventually planned.
=item * Although I like keeping warnings associated with the ebook
object, it may be better to throw exceptions on errors and catch them
later. This probably won't be implemented until it bites someone who
complains, though.
=item * Unit tests are incomplete
=back
=head1 AUTHOR
Zed Pobre <zed@debian.org>
=head1 LICENSE AND COPYRIGHT
Copyright 2008-2013 Zed Pobre
Licensed to the public under the terms of the GNU GPL, version 2
=cut
1;
( run in 0.720 second using v1.01-cache-2.11-cpan-39bf76dae61 )