summaryrefslogtreecommitdiff
path: root/lib/Derf/Visual/WeatherIcons.pm.PL
blob: b090380a3870482a8a26c5f5b318ca79f3f2ad12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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__