| 1 | package Template::Plugin::Catalyst::View::PDF::Reuse::Barcode; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use parent 'Template::Plugin'; | ||
| 6 | |||
| 7 | our $AUTOLOAD; | ||
| 8 | our $target = 'PDF::Reuse::Barcode'; | ||
| 9 | |||
| 10 | # Adapted from Template::Plugin::Procedural by Mark Fowler | ||
| 11 | sub load { | ||
| 12 | my ($class, $context) = @_; | ||
| 13 | |||
| 14 | my $proxy = "Template::Plugin::" . $class; | ||
| 15 | eval "use $target"; | ||
| 16 | no strict "refs"; | ||
| 17 | if ($@) { | ||
| 18 | my $error = $@; | ||
| 19 | *{ $proxy . "::AUTOLOAD" } = sub { | ||
| 20 | $AUTOLOAD =~ s!^.*::!!; | ||
| 21 | die "Cannot load $target so unable to execute '$AUTOLOAD' in template - $error" | ||
| 22 | unless ($AUTOLOAD eq 'DESTROY'); | ||
| 23 | }; | ||
| 24 | } else { | ||
| 25 | *{ $proxy . "::AUTOLOAD" } = sub { | ||
| 26 | $AUTOLOAD =~ s!^.*::!!; | ||
| 27 | if (my $method = $target->can($AUTOLOAD)) { | ||
| 28 | shift @_; | ||
| 29 | |||
| 30 | # Expand hashref arguments for PDF::Reuse::Barcode | ||
| 31 | if (ref $_[0] eq 'HASH') { | ||
| 32 | splice @_,0,1,%{$_[0]}; | ||
| 33 | } | ||
| 34 | |||
| 35 | goto $method; | ||
| 36 | } else { | ||
| 37 | warn "Cannot find method $AUTOLOAD in $target"; | ||
| 38 | } | ||
| 39 | }; | ||
| 40 | } | ||
| 41 | |||
| 42 | *{ $proxy . "::new" } = sub { | ||
| 43 | my $this; | ||
| 44 | return bless \$this, $_[0]; | ||
| 45 | }; | ||
| 46 | |||
| 47 | return $proxy; | ||
| 48 | } | ||
| 49 | |||
| 50 | |||
| 51 | =head1 NAME | ||
| 52 | |||
| 53 | Template::Plugin::Catalyst::View::PDF::Reuse | ||
| 54 | |||
| 55 | =head1 SYNOPSYS | ||
| 56 | |||
| 57 | Template Toolkit plugin for PDF::Reuse | ||
| 58 | |||
| 59 | =head1 AUTHOR | ||
| 60 | |||
| 61 | Jon Allen, L<jj@jonallen.info> | ||
| 62 | |||
| 63 | =head1 SEE ALSO | ||
| 64 | |||
| 65 | Penny's Arcade Open Source - L<http://www.pennysarcade.co.uk/opensource> | ||
| 66 | |||
| 67 | =head1 COPYRIGHT & LICENSE | ||
| 68 | |||
| 69 | Copyright 2009 Penny's Arcade Limited, all rights reserved. | ||
| 70 | |||
| 71 | This program is free software; you can redistribute it and/or modify it | ||
| 72 | under the same terms as Perl itself. | ||
| 73 | |||
| 74 | =cut | ||
| 75 | |||
| 76 | 1; |