From ef76ccd91ecddafb953554b6d4847a651e338d99 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 1 Mar 2011 21:43:21 +0100 Subject: Make options intuitive for both GetOptions-passing and manual setup --- bin/dthumb | 2 +- lib/App/Dthumb.pm | 38 ++++++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/bin/dthumb b/bin/dthumb index fa3f975..bd27f5c 100755 --- a/bin/dthumb +++ b/bin/dthumb @@ -30,7 +30,7 @@ GetOptions( }, ) or die("Please see perldoc -F $0\n"); -my $dthumb = App::Dthumb->new($opt); +my $dthumb = App::Dthumb->new(%{$opt}); my $timer = Time::Progress->new(); diff --git a/lib/App/Dthumb.pm b/lib/App/Dthumb.pm index c4b7102..ecde021 100755 --- a/lib/App/Dthumb.pm +++ b/lib/App/Dthumb.pm @@ -47,7 +47,7 @@ use Cwd; use Image::Imlib2; our @EXPORT_OK = (); -our $VERSION = '0.1'; +our $VERSION = '0.2'; =head1 METHODS @@ -111,30 +111,32 @@ Default: false sub new { - my ($obj, $conf) = @_; + my ($obj, %conf) = @_; my $ref = {}; - $conf->{size} //= 200; - $conf->{spacing} //= 1.1; - $conf->{quality} //= 75; - $conf->{title} //= (split(qr{/}, cwd()))[-1]; - $conf->{lightbox} = !$conf->{'no-lightbox'}; - $conf->{names} = !$conf->{'no-names'}; + $conf{size} //= 200; + $conf{spacing} //= 1.1; + $conf{quality} //= 75; + $conf{title} //= (split(qr{/}, cwd()))[-1]; + $conf{file_index} //= 'index.xhtml'; + $conf{dir_thumbs} //= '.thumbs'; + $conf{dir_data} //= '.dthumb'; + - $ref->{config} = $conf; + # helpers to directly pass GetOptions results + $conf{lightbox} //= !$conf{'no-lightbox'}; + $conf{names} //= !$conf{'no-names'}; + + $ref->{config} = \%conf; $ref->{data} = App::Dthumb::Data->new(); $ref->{data}->set_vars( - title => $conf->{title}, - width => $conf->{size} * $conf->{spacing} . 'px', - height => $conf->{size} * $conf->{spacing} . 'px', + title => $conf{title}, + width => $conf{size} * $conf{spacing} . 'px', + height => $conf{size} * $conf{spacing} . 'px', ); - $ref->{config}->{file_index} = 'index.xhtml'; - $ref->{config}->{dir_thumbs} = '.thumbs'; - $ref->{config}->{dir_data} = '.dthumb'; - $ref->{html} = $ref->{data}->get('html_start'); return bless($ref, $obj); @@ -364,6 +366,10 @@ sub write_out_html { close($fh); } +sub version { + return $VERSION; +} + 1; __END__ -- cgit v1.2.3