| 1 | package PDF::Boxer; | ||||||||||
| 2 | { | ||||||||||
| 3 | 3 | $PDF::Boxer::VERSION = '0.004'; | |||||||||
| 4 | } | ||||||||||
| 5 | 3 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | # ABSTRACT: Create PDFs from a simple box markup language. | ||||||||||
| 8 | |||||||||||
| 9 | |||||||||||
| 10 | 3 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 3 | ▶ | use PDF::Boxer::Doc; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 3 | ▶ | use PDF::Boxer::Content::Box; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 3 | ▶ | use PDF::Boxer::Content::Text; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 3 | ▶ | use PDF::Boxer::Content::Image; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 3 | ▶ | use PDF::Boxer::Content::Row; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 3 | ▶ | use PDF::Boxer::Content::Column; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 3 | ▶ | use PDF::Boxer::Content::Grid; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 3 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 3 | ▶ | use Scalar::Util qw/weaken/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 3 | ▶ | use Moose::Util::TypeConstraints; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | coerce 'PDF::Boxer::Doc' | ||||||||||
| 24 | => from 'HashRef' | ||||||||||
| 25 | 0 | ▶ | => via { PDF::Boxer::Doc->new($_) }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 26 | |||||||||||
| 27 | 3 | has 'debug' => ( isa => 'Bool', is => 'ro', default => 0 ); | |||||||||
| 28 | |||||||||||
| 29 | 3 | has 'doc' => ( isa => 'PDF::Boxer::Doc', is => 'ro', coerce => 1, lazy_build => 1 ); | |||||||||
| 30 | |||||||||||
| 31 | 3 | has 'max_width' => ( isa => 'Int', is => 'rw', default => 595 ); | |||||||||
| 32 | 3 | has 'max_height' => ( isa => 'Int', is => 'rw', default => 842 ); | |||||||||
| 33 | |||||||||||
| 34 | 0 | ▶ | has 'box_register' => ( isa => 'HashRef', is => 'ro', default => sub{{}} ); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 35 | |||||||||||
| 36 | 0 | ▶ | sub _build_doc{ | ||||||||
|
Subroutine
_build_doc: not called CC=1 SCAR=6.9
| |||||||||||
| 37 | 0 | my ($self) = @_; | |||||||||
| 38 | 0 | return PDF::Boxer::Doc->new; | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 0 | ▶ | sub register_box{ | ||||||||
|
Subroutine
register_box: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 42 | 0 | my ($self, $box) = @_; | |||||||||
| 43 | 0 | ▶ | return unless $box->name; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | weaken($box); | |||||||||
| 45 | 0 | $self->box_register->{$box->name} = $box; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | sub box_lookup{ | ||||||||
|
Subroutine
box_lookup: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 49 | 0 | my ($self, $name) = @_; | |||||||||
| 50 | 0 | return $self->box_register->{$name}; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 0 | ▶ | sub add_to_pdf{ | ||||||||
|
Subroutine
add_to_pdf: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 54 | 0 | my ($self, $spec) = @_; | |||||||||
| 55 | |||||||||||
| 56 | 0 | my $weak_me = $self; | |||||||||
| 57 | 0 | weaken($weak_me); | |||||||||
| 58 | 0 | $spec->{boxer} = $weak_me; | |||||||||
| 59 | 0 | $spec->{debug} = $self->debug; | |||||||||
| 60 | |||||||||||
| 61 | 0 | ▶ | if ($spec->{type} eq 'Doc'){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 0 | foreach my $page (@{$spec->{children}}){ | |||||||||
| 63 | 0 | $page->{boxer} = $weak_me; | |||||||||
| 64 | 0 | $page->{debug} = $self->debug; | |||||||||
| 65 | |||||||||||
| 66 | 0 | my $class = 'PDF::Boxer::Content::'.$page->{type}; | |||||||||
| 67 | 0 | my $node = $class->new($page); | |||||||||
| 68 | 0 | $self->register_box($node); | |||||||||
| 69 | 0 | $node->initialize; | |||||||||
| 70 | 0 | $node->render; | |||||||||
| 71 | 0 | $self->doc->new_page; | |||||||||
| 72 | } | ||||||||||
| 73 | } else { | ||||||||||
| 74 | 0 | my $class = 'PDF::Boxer::Content::'.$spec->{type}; | |||||||||
| 75 | 0 | my $node = $class->new($spec); | |||||||||
| 76 | 0 | $self->register_box($node); | |||||||||
| 77 | 0 | $node->initialize; | |||||||||
| 78 | 0 | $node->render; | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 0 | return 1; | |||||||||
| 82 | #return $node; | ||||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 0 | ▶ | sub finish{ | ||||||||
|
Subroutine
finish: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 86 | 0 | my ($self) = @_; | |||||||||
| 87 | 0 | $self->doc->pdf->save; | |||||||||
| 88 | 0 | $self->doc->pdf->end; | |||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||
| 92 | |||||||||||
| 93 | 3 | 1; | |||||||||
| 94 | |||||||||||
| 95 | __END__ | ||||||||||