File Coverage

lib/PDF/WebKit/Configuration.pm
Criterion Covered Total %
statement 22 24 91.6
branch 2 4 50.0
condition 2 3 66.6
subroutine 7 7 100.0
pod 0 2 0.0
total 33 40 82.5


line stmt bran cond sub pod time code
1             package PDF::WebKit::Configuration;
2 3     3   16 use strict;
  3         5  
  3         72  
3 3     3   12 use warnings;
  3         4  
  3         58  
4 3     3   1408 use Moo;
  3         27474  
  3         18  
5 3     3   4906 use namespace::clean;
  3         27205  
  3         15  
6              
7             has meta_tag_prefix => ( is => 'rw' );
8             has default_options => ( is => 'rw' );
9             has wkhtmltopdf => ( is => 'rw', builder => '_find_wkhtmltopdf', lazy => 1 );
10              
11             around 'BUILDARGS' => sub {
12             my $orig = shift;
13             my $self = shift;
14             return $self->$orig({
15             meta_tag_prefix => 'pdf-webkit-',
16             default_options => {
17             disable_smart_shrinking => undef,
18             page_size => 'Letter',
19             margin_top => '0.75in',
20             margin_right => '0.75in',
21             margin_bottom => '0.75in',
22             margin_left => '0.75in',
23             encoding => "UTF-8",
24             },
25             });
26             };
27              
28             sub _find_wkhtmltopdf {
29 1     1   53 my $self = shift;
30 1 50       3 my $which = $^O eq "MSWin32" ? "where" : "which";
31 1         2600 my $found = `$which wkhtmltopdf`;
32 1 50       44 if ($? == 0) {
33 0         0 chomp($found);
34 0         0 return $found;
35             }
36             else {
37 1         44 return undef;
38             }
39             }
40              
41             my $_config;
42             sub configuration {
43 48   66 48 0 603 $_config ||= PDF::WebKit::Configuration->new;
44             }
45              
46             sub configure {
47 2     2 0 37 my $class = shift;
48 2         2 my $code = shift;
49 2         4 local $_ = $class->configuration;
50 2         4 $code->($_);
51             }
52              
53             1;