File Coverage

lib/PDF/WebKit/Configuration.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


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