| 1 | package App::Dthumb::Data; | ||||||||||
| 2 | |||||||||||
| 3 | |||||||||||
| 4 | =head1 NAME | ||||||||||
| 5 | |||||||||||
| 6 | App::Dthumb::Data - Retrieve installed data (like lightbox images) | ||||||||||
| 7 | |||||||||||
| 8 | =head1 SYNOPSIS | ||||||||||
| 9 | |||||||||||
| 10 | use App::Dthumb::Data; | ||||||||||
| 11 | my $data = App::Dthumb::Data->new(); | ||||||||||
| 12 | |||||||||||
| 13 | $data->set_vars( | ||||||||||
| 14 | title => 'Something funky', | ||||||||||
| 15 | ); | ||||||||||
| 16 | |||||||||||
| 17 | print $data->get('html_start.dthumb'); | ||||||||||
| 18 | |||||||||||
| 19 | open(my $fh, '>', 'close.png'); | ||||||||||
| 20 | print {$fh} $data->get('close.png'); | ||||||||||
| 21 | close($fh); | ||||||||||
| 22 | |||||||||||
| 23 | =head1 VERSION | ||||||||||
| 24 | |||||||||||
| 25 | This manual documents B<App::Dthumb::Data> version 0.2 | ||||||||||
| 26 | |||||||||||
| 27 | =cut | ||||||||||
| 28 | |||||||||||
| 29 | |||||||||||
| 30 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 2 | ▶ | use base 'Exporter'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | |||||||||||
| 34 | 2 | ▶ | use Data::Section -setup; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 35 | 2 | ▶ | use MIME::Base64 qw(decode_base64); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | |||||||||||
| 37 | 2 | our @EXPORT_OK = (); | |||||||||
| 38 | 2 | our $VERSION = '0.2'; | |||||||||
| 39 | |||||||||||
| 40 | |||||||||||
| 41 | =head1 METHODS | ||||||||||
| 42 | |||||||||||
| 43 | =head2 new | ||||||||||
| 44 | |||||||||||
| 45 | Returns a new B<App::Dthumb> object. Does not take any arguments. | ||||||||||
| 46 | |||||||||||
| 47 | =cut | ||||||||||
| 48 | |||||||||||
| 49 | |||||||||||
| 50 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 51 | 1 | my ($obj) = @_; | |||||||||
| 52 | 1 | my $ref = {}; | |||||||||
| 53 | 1 | return bless($ref, $obj); | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | |||||||||||
| 57 | =head2 set_vars(%vars) | ||||||||||
| 58 | |||||||||||
| 59 | Set replacement variables. For each hash key, when outputting data using the | ||||||||||
| 60 | B<get> function, dthumb will replace occurences of "<!-- $key -->" or "/* $key | ||||||||||
| 61 | */" (the dollar sign is literal) with its value. | ||||||||||
| 62 | |||||||||||
| 63 | =cut | ||||||||||
| 64 | |||||||||||
| 65 | |||||||||||
| 66 | 0 | ▶ | sub set_vars { | ||||||||
|
Subroutine
set_vars: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 67 | 0 | my ($self, %vars) = @_; | |||||||||
| 68 | 0 | $self->{replace} = \%vars; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | |||||||||||
| 72 | =head2 list_archived | ||||||||||
| 73 | |||||||||||
| 74 | Returns an array of all saved data. That is, all files which do not end in | ||||||||||
| 75 | ".dthumb". | ||||||||||
| 76 | |||||||||||
| 77 | =cut | ||||||||||
| 78 | |||||||||||
| 79 | |||||||||||
| 80 | 0 | ▶ | sub list_archived { | ||||||||
|
Subroutine
list_archived: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 81 | 0 | my ($self) = @_; | |||||||||
| 82 | 0 | return grep { ! /\.dthumb$/ } $self->section_data_names(); | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | |||||||||||
| 86 | =head2 get($filename) | ||||||||||
| 87 | |||||||||||
| 88 | Returns the exact content of share/$filename. | ||||||||||
| 89 | |||||||||||
| 90 | =cut | ||||||||||
| 91 | |||||||||||
| 92 | |||||||||||
| 93 | 8 | ▶ | sub get { | ||||||||
|
Subroutine
get: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||
| 94 | 8 | my ($self, $name) = @_; | |||||||||
| 95 | 8 | my $data = $self->section_data($name); | |||||||||
| 96 | |||||||||||
| 97 | 8 | ▶ | if (not $data) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | 0 | die("No such data: ${name}\n"); | |||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | 8 | $data = ${$data}; | |||||||||
| 102 | |||||||||||
| 103 | 8 | chomp($data); | |||||||||
| 104 | |||||||||||
| 105 | 8 | ▶ | if ($name =~ qr{ \. (png | gif) $ }ox) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | 3 | return decode_base64($data); | |||||||||
| 107 | } | ||||||||||
| 108 | |||||||||||
| 109 | 5 | ▶ | while (my ($key, $value) = each %{$self->{replace}}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 110 | 0 | $data =~ s{ | |||||||||
| 111 | ( \<\!-- | /\* ) | ||||||||||
| 112 | \s+ \$ $key \s+ | ||||||||||
| 113 | ( --\> | \*/ ) | ||||||||||
| 114 | }{$value}gx; | ||||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | 5 | return $data; | |||||||||
| 118 | } | ||||||||||
| 119 | |||||||||||
| 120 | 2 | 1; | |||||||||
| 121 | |||||||||||
| 122 | =head1 DEPENDENCIES | ||||||||||
| 123 | |||||||||||
| 124 | =over | ||||||||||
| 125 | |||||||||||
| 126 | =item * Data::Section | ||||||||||
| 127 | |||||||||||
| 128 | =back | ||||||||||
| 129 | |||||||||||
| 130 | =head1 AUTHOR | ||||||||||
| 131 | |||||||||||
| 132 | Copyright (C) 2011 by Daniel Friesel E<lt>derf@chaosdorf.deE<gt> | ||||||||||
| 133 | |||||||||||
| 134 | =head1 LICENSE | ||||||||||
| 135 | |||||||||||
| 136 | 0. You just DO WHAT THE FUCK YOU WANT TO. | ||||||||||
| 137 | |||||||||||
| 138 | =cut | ||||||||||
| 139 | |||||||||||
| 140 | __DATA__ | ||||||||||