| 1 | package App::Images::To::DjVu; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Class::Utils qw(set_params); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Error::Pure qw(err); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Getopt::Std; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Perl6::Slurp qw(slurp); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | our $VERSION = 0.02; | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | # Constructor. | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | my ($class, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | # Create object. | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | # Process parameters. | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | set_params($self, @params); | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | # Object. | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | # Run. | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=12 SCAR=42.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | # Process arguments. | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | $self->{'_opts'} = { | |||||||||||||||||||||||||||||||||||||||||
| 34 | 'e' => 'c44', | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 'h' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 'o' => 'output.djvu', | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 'q' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 38 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | if (! getopts('e:ho:q', $self->{'_opts'}) || @ARGV < 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not &getopts("e:ho:q", $self->{"_opts"}) or @ARGV < 1 or $self->{"_opts"}{"h"}
not &getopts("e:ho:q", $self->{"_opts"}) or @ARGV < 1
MC/DC0%0/3
not &getopts("e:ho:q", $self->{"_opts"}) or @ARGV < 1 or $self->{"_opts"}{"h"}
not &getopts("e:ho:q", $self->{"_opts"})
@ARGV < 1
$self->{"_opts"}{"h"}
Truth table25%1/4
not(A) or B or C
A= not &getopts("e:ho:q", $self->{"_opts"})B= @ARGV < 1C= $self->{"_opts"}{"h"}
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | || $self->{'_opts'}->{'h'}) { | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | print STDERR "Usage: $0 [-e encoder] [-h] [-o out_file] [-q] ". | |||||||||||||||||||||||||||||||||||||||||
| 43 | "[--version] images_list_file\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | print STDERR "\t-e encoder\t\tEncoder (default value is 'c44').\n"; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | print STDERR "\t-h\t\t\tPrint help.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | print STDERR "\t-o out_file\t\tOutput file (default value is ". | |||||||||||||||||||||||||||||||||||||||||
| 47 | "'output.djvu').\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | print STDERR "\t-q\t\t\tQuiet mode.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | print STDERR "\t--version\t\tPrint version.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | print STDERR "\timages_list_file\tText file with images list.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $images_list_file = $ARGV[0]; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | # Get images. | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my @images = slurp($images_list_file, { 'chomp' => 1 }); | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | # Create djvu file for each file. | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my @djvu; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | foreach my $image (@images) { | |||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my ($image_base, undef, $suffix) = fileparse($image, qr{\.[^.]+$}); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $suffix =~ s/^\.//ms; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my $djvu = $image_base.'.djvu'; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | push @djvu, $djvu; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ($image ne $djvu && ! -r $djvu) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$image ne $djvu and not -r $djvu
MC/DC0%0/2
$image ne $djvu and not -r $djvu
$image ne $djvu
not -r $djvu
Truth table0%0/3
A and not(B)
A= $image ne $djvuB= not -r $djvu
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ($self->{'_opts'}->{'e'} eq 'c44') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ($suffix eq 'png') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | system "convert $image $image_base.jpg"; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $image = "$image_base.jpg"; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | system "c44 $image $djvu"; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if (! $self->{'_opts'}->{'q'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | print "$djvu\n"; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | err "Unsupported encoder '$self->{'_opts'}->{'e'}'."; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | # Create djvu file. | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if (! -r $self->{'_opts'}->{'o'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | system "djvm -c $self->{'_opts'}->{'o'} ".(join ' ', @djvu); | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if (! $self->{'_opts'}->{'q'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | print "$self->{'_opts'}->{'o'}\n"; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | App::Images::To::DjVu - Base class for images2djvu script. | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | use App::Images::To::DjVu; | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | my $app = App::Images::To::DjVu->new; | ||||||||||||||||||||||||||||||||||||||||||
| 107 | my $exit_code = $app->run; | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | =head2 C<new> | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | my $app = App::Images::To::DjVu->new; | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | Constructor. | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | Returns instance of object. | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | =head2 C<run> | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | my $exit_code = $app->run; | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | Run. | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | Returns 1 for error, 0 for success. | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | =head1 ERRORS | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | new(): | ||||||||||||||||||||||||||||||||||||||||||
| 130 | From Class::Utils::set_params(): | ||||||||||||||||||||||||||||||||||||||||||
| 131 | Unknown parameter '%s'. | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | run(): | ||||||||||||||||||||||||||||||||||||||||||
| 134 | Unsupported encoder '%s'. | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | =head1 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | use strict; | ||||||||||||||||||||||||||||||||||||||||||
| 139 | use warnings; | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | use App::Images::To::DjVu; | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | # Arguments. | ||||||||||||||||||||||||||||||||||||||||||
| 144 | @ARGV = ( | ||||||||||||||||||||||||||||||||||||||||||
| 145 | '-h', | ||||||||||||||||||||||||||||||||||||||||||
| 146 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | # Run. | ||||||||||||||||||||||||||||||||||||||||||
| 149 | exit App::Images::To::DjVu->new->run; | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | # Output like: | ||||||||||||||||||||||||||||||||||||||||||
| 152 | # Usage: ./ex1.pl [-e encoder] [-h] [-o out_file] [-q] [--version] images_list_file | ||||||||||||||||||||||||||||||||||||||||||
| 153 | # -e encoder Encoder (default value is 'c44'). | ||||||||||||||||||||||||||||||||||||||||||
| 154 | # -h Print help. | ||||||||||||||||||||||||||||||||||||||||||
| 155 | # -o out_file Output file (default value is 'output.djvu'). | ||||||||||||||||||||||||||||||||||||||||||
| 156 | # -q Quiet mode. | ||||||||||||||||||||||||||||||||||||||||||
| 157 | # --version Print version. | ||||||||||||||||||||||||||||||||||||||||||
| 158 | # images_list_file Text file with images list. | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | =head1 DEPENDENCIES | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | L<Class::Utils>, | ||||||||||||||||||||||||||||||||||||||||||
| 163 | L<Error::Pure>, | ||||||||||||||||||||||||||||||||||||||||||
| 164 | L<File::Basename>, | ||||||||||||||||||||||||||||||||||||||||||
| 165 | L<Getopt::Std>, | ||||||||||||||||||||||||||||||||||||||||||
| 166 | L<Perl6::Slurp>. | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | =head1 REPOSITORY | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | L<https://github.com/michal-josef-spacek/App-Images-To-DjVu> | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | Michal Josef Špaček L<mailto:skim@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | L<http://skim.cz> | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | © 2021-2022 Michal Josef Špaček | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | BSD 2-Clause License | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0.02 | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | =cut | ||||||||||||||||||||||||||||||||||||||||||