From c121656622ee63a0983c86df9be7857b5303a4c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kay=20Sindre=20B=C3=A6rulfsen?= Date: Tue, 13 Oct 2020 21:34:36 +0200 Subject: [PATCH 1/2] Support for command line arguments with multiple values Some of the command line arguments supported by wkhtmltopdf requires more than one value (--cookie and --custom-header). This patch allow users to specify multiple values by passing a array-ref. --- lib/PDF/WebKit.pm | 5 ++++- t/pdf-webkit.t | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/PDF/WebKit.pm b/lib/PDF/WebKit.pm index 5e83e5b..a62112d 100644 --- a/lib/PDF/WebKit.pm +++ b/lib/PDF/WebKit.pm @@ -194,7 +194,7 @@ sub _prepare_options { push @args, $name; } else { - push @args, $name, $val; + push @args, $name, (ref($val) eq 'ARRAY') ? @$val : $val; } } return @args; @@ -271,6 +271,9 @@ C<< PDF::WebKit->configure >> class method: $_->meta_tag_prefix('my-prefix-'); $_->default_options->{'--orientation'} = 'Portrait'; + + # Some options expects multiple values + $_->default_options->{'--custom-header'} = ['DNT', '1']; }); See the L method for the standard default options. diff --git a/t/pdf-webkit.t b/t/pdf-webkit.t index 17b3230..510cda8 100644 --- a/t/pdf-webkit.t +++ b/t/pdf-webkit.t @@ -106,6 +106,13 @@ describe "PDF::WebKit" => sub { like( $command[index_of('--no-collate',@command) + 1], qr/^-/ ); }; + it "should accept multiple values" => sub { + my $pdfkit = PDF::WebKit->new(\'html', '--custom-header' => [ 'X-Foo', 'bar bas' ] ); + my @command = $pdfkit->command; + is( $command[index_of('--custom-header',@command) + 1], 'X-Foo' ); + is( $command[index_of('--custom-header',@command) + 2], 'bar bas' ); + }; + it "should encapsulate string arguments in quotes" => sub { my $pdfkit = PDF::WebKit->new(\'html', header_center => "foo [page]"); my @command = $pdfkit->command; From 9dae0a9fc24b9aeb788a889a9b92e47c87c2f7c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kay=20Sindre=20B=C3=A6rulfsen?= Date: Tue, 13 Oct 2020 21:40:44 +0200 Subject: [PATCH 2/2] Fixed indenting in test --- t/pdf-webkit.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/pdf-webkit.t b/t/pdf-webkit.t index 510cda8..d45266d 100644 --- a/t/pdf-webkit.t +++ b/t/pdf-webkit.t @@ -107,7 +107,7 @@ describe "PDF::WebKit" => sub { }; it "should accept multiple values" => sub { - my $pdfkit = PDF::WebKit->new(\'html', '--custom-header' => [ 'X-Foo', 'bar bas' ] ); + my $pdfkit = PDF::WebKit->new(\'html', '--custom-header' => [ 'X-Foo', 'bar bas' ] ); my @command = $pdfkit->command; is( $command[index_of('--custom-header',@command) + 1], 'X-Foo' ); is( $command[index_of('--custom-header',@command) + 2], 'bar bas' );