diff options
author | Daniel Friesel <derf@finalrewind.org> | 2011-03-07 17:37:11 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2011-03-07 17:37:11 +0100 |
commit | ad56a62ae06c72d188d435dd45961a3c487f7839 (patch) | |
tree | 3b4f195eb03721abb157ef8316a3b574ad72061e | |
parent | be6a8fc3771d002862e645eeec84e30791badd02 (diff) |
-> Module::Build and Derf::Visual
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | Build.PL | 27 | ||||
-rwxr-xr-x | bin/vweather | 20 | ||||
-rw-r--r-- | lib/Derf/Visual/WeatherIcons.pm.PL | 75 |
4 files changed, 111 insertions, 15 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8f6a118 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/Build +/_build/ +/blib/ +/lib/Derf/Visual/WeatherIcons.pm diff --git a/Build.PL b/Build.PL new file mode 100644 index 0000000..b2803d0 --- /dev/null +++ b/Build.PL @@ -0,0 +1,27 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Module::Build; + +my $build = Module::Build->new( + build_requires => { + 'Test::More' => 0, + 'Test::Compile' => 0, + 'Test::Pod' => 0, + }, + dist_abstract => 'Cheap PNG widgets for the lulz', + dist_name => 'visual', + dist_version => '0.0', + license => 'unrestricted', + PL_files => { + 'lib/Derf/Visual/WeatherIcons.pm.PL' => + 'lib/Derf/Visual/WeatherIcons.pm', + }, + requires => { + 'perl' => '5.10.0', + 'autodie' => 0, + }, + sign => 1, +); +$build->create_build_script(); diff --git a/bin/vweather b/bin/vweather index 0c7f337..b04a203 100755 --- a/bin/vweather +++ b/bin/vweather @@ -7,6 +7,7 @@ use warnings; use 5.010; use autodie; +use Derf::Visual::WeatherIcons; use GD; use Getopt::Std; use Term::ANSIColor; @@ -15,7 +16,7 @@ use Weather::Google; my %opt; my $alpha; my $dump; -my $share = $0; +my $iconstore = Derf::Visual::WeatherIcons->new(); my $weather = Weather::Google->new( 'Essen, Germany', @@ -86,11 +87,11 @@ sub show_weather_png { $high , $red); if ($dump) { - say "${share}/weather/${icon}"; + say $icon; } - if (-e "${share}/weather/${icon}") { - my $tmp = GD::Image->newFromPng("${share}/weather/${icon}", 1); + if ($iconstore->exists($icon)) { + my $tmp = GD::Image->newFromPngData($iconstore->get($icon), 1); $im->copy($tmp, $x_offset + $offset_icon, $y_offset, 0, 0, 16, 16); } } @@ -107,17 +108,6 @@ getopts('a:cdfg', \%opt); $alpha = $opt{'a'} // 40; $dump = $opt{'d'} // 0; -if (-l $share) { - my $link = readlink($share); - $share =~ s{ [^/]+ $ }{}x; - $link =~ s{ / bin / vweather $ }{}x; - $share .= "${link}/share"; -} -else { - $share =~ s{ / bin / vweather $ }{}x; - $share .= '/share'; -} - if ($opt{'c'}) { show_weather_console(); } diff --git a/lib/Derf/Visual/WeatherIcons.pm.PL b/lib/Derf/Visual/WeatherIcons.pm.PL new file mode 100644 index 0000000..b090380 --- /dev/null +++ b/lib/Derf/Visual/WeatherIcons.pm.PL @@ -0,0 +1,75 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.010; + +use autodie; +use MIME::Base64 qw(encode_base64); + +my ($out_file) = @ARGV; +my $share_dir = 'share/weather'; + +open(my $out_fh, '>', $out_file); +opendir(my $share_dh, $share_dir); + +print {$out_fh} <DATA>; + +for my $file (readdir($share_dh)) { + if (not -l "${share_dir}/${file}") { + next; + } + + open(my $fh, '<', "${share_dir}/${file}"); + my $content = do { local $/ = undef; <$fh> }; + close($fh); + + printf {$out_fh} ( + "______[ %s ]______\n%s\n", + $file, + encode_base64($content), + ); +} +closedir($share_dh); +close($out_fh); + + +__DATA__ +package Derf::Visual::WeatherIcons; +use strict; +use warnings; +use base 'Exporter'; +use Data::Section -setup; +use MIME::Base64 qw(decode_base64); + +our @EXPORT_OK = (); +our $VERSION = '0.1'; + +sub new { + my ($obj) = @_; + my $ref = {}; + return bless($ref, $obj); +} + +sub exists { + my ($self, $name) = @_; + + if (defined $self->section_data($name)) { + return 1; + } + return 0; +} + +sub get { + my ($self, $name) = @_; + my $data = $self->section_data($name); + + if (not $data) { + return undef; + } + + return decode_base64(${$data}); +} + +1; + +__DATA__ |