« lib/PDF/FromHTML/Template/Container/Section.pm
↑ Summary
lib/PDF/FromHTML/Template/Element/Circle.pm »
| 1 | package PDF::FromHTML::Template::Base; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | |||
| 5 | BEGIN { | ||
| 6 | } | ||
| 7 | |||
| 8 | use PDF::FromHTML::Template::Constants qw( | ||
| 9 | %Verify | ||
| 10 | ); | ||
| 11 | |||
| 12 | use PDF::FromHTML::Template::Factory; | ||
| 13 | |||
| 14 | sub new | ||
| 15 | { | ||
| 16 | my $class = shift; | ||
| 17 | |||
| 18 | push @_, %{shift @_} while UNIVERSAL::isa($_[0], 'HASH'); | ||
| 19 | (@_ % 2) && die "$class->new() called with odd number of option parameters", $/; | ||
| 20 | |||
| 21 | my %x = @_; | ||
| 22 | |||
| 23 | # Do not use a hashref-slice here because of the uppercase'ing | ||
| 24 | my $self = {}; | ||
| 25 | $self->{uc $_} = $x{$_} for keys %x; | ||
| 26 | |||
| 27 | $self->{__THIS_HAS_RENDERED__} = 0; | ||
| 28 | |||
| 29 | bless $self, $class; | ||
| 30 | } | ||
| 31 | |||
| 32 | sub isa { PDF::FromHTML::Template::Factory::isa(@_) } | ||
| 33 | |||
| 34 | # These functions are used in the P::T::Container & P::T::Element hierarchies | ||
| 35 | |||
| 36 | sub _validate_option | ||
| 37 | { | ||
| 38 | my $self = shift; | ||
| 39 | my ($option, $val_ref) = @_; | ||
| 40 | |||
| 41 | $option = uc $option; | ||
| 42 | return 1 unless exists $Verify{$option} && UNIVERSAL::isa($Verify{$option}, 'HASH'); | ||
| 43 | |||
| 44 | if (defined $val_ref) | ||
| 45 | { | ||
| 46 | if (!defined $$val_ref) | ||
| 47 | { | ||
| 48 | $$val_ref = $Verify{$option}{'__DEFAULT__'}; | ||
| 49 | } | ||
| 50 | elsif (!exists $Verify{$option}{$$val_ref}) | ||
| 51 | { | ||
| 52 | my $name = ucfirst lc $option; | ||
| 53 | warn "$name '$$val_ref' unsupported. Defaulting to '$Verify{$option}{'__DEFAULT__'}'", $/; | ||
| 54 | $$val_ref = $Verify{$option}{'__DEFAULT__'}; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | elsif (!defined $self->{$option}) | ||
| 58 | { | ||
| 59 | $self->{$option} = $Verify{$option}{'__DEFAULT__'}; | ||
| 60 | } | ||
| 61 | elsif (!exists $Verify{$option}{$self->{$option}}) | ||
| 62 | { | ||
| 63 | my $name = ucfirst lc $option; | ||
| 64 | warn "$name '$self->{$option}' unsupported. Defaulting to '$Verify{$option}{'__DEFAULT__'}'", $/; | ||
| 65 | $self->{$option} = $Verify{$option}{'__DEFAULT__'}; | ||
| 66 | } | ||
| 67 | |||
| 68 | return 1; | ||
| 69 | } | ||
| 70 | |||
| 71 | sub calculate { ($_[1])->get(@_[0,2]) } | ||
| 72 | #{ | ||
| 73 | # my $self = shift; | ||
| 74 | # my ($context, $attr) = @_; | ||
| 75 | # | ||
| 76 | # return $context->get($self, $attr); | ||
| 77 | #} | ||
| 78 | |||
| 79 | sub enter_scope { ($_[1])->enter_scope($_[0]) } | ||
| 80 | #{ | ||
| 81 | # my $self = shift; | ||
| 82 | # my ($context) = @_; | ||
| 83 | # | ||
| 84 | # return $context->enter_scope($self); | ||
| 85 | #} | ||
| 86 | |||
| 87 | sub exit_scope { ($_[1])->exit_scope(@_[0, 2]) } | ||
| 88 | #{ | ||
| 89 | # my $self = shift; | ||
| 90 | # my ($context, $no_delta) = @_; | ||
| 91 | # | ||
| 92 | # return $context->exit_scope($self, $no_delta); | ||
| 93 | #} | ||
| 94 | |||
| 95 | sub deltas | ||
| 96 | { | ||
| 97 | # my $self = shift; | ||
| 98 | # my ($context) = @_; | ||
| 99 | |||
| 100 | return {}; | ||
| 101 | } | ||
| 102 | |||
| 103 | sub reset { $_[0]{__THIS_HAS_RENDERED__} = 0 } | ||
| 104 | sub mark_as_rendered { $_[0]{__THIS_HAS_RENDERED__} = 1 } | ||
| 105 | sub has_rendered { $_[0]{__THIS_HAS_RENDERED__} } | ||
| 106 | sub should_render { ($_[0]{__THIS_HAS_RENDERED__}) || (($_[1])->should_render($_[0])) } | ||
| 107 | |||
| 108 | sub resolve | ||
| 109 | { | ||
| 110 | # my $self = shift; | ||
| 111 | # my ($context) = @_; | ||
| 112 | |||
| 113 | ''; | ||
| 114 | } | ||
| 115 | |||
| 116 | sub render | ||
| 117 | { | ||
| 118 | # my $self = shift; | ||
| 119 | # my ($context) = @_; | ||
| 120 | |||
| 121 | return 1; | ||
| 122 | } | ||
| 123 | |||
| 124 | sub begin_page | ||
| 125 | { | ||
| 126 | # my $self = shift; | ||
| 127 | # my ($context) = @_; | ||
| 128 | |||
| 129 | return 1; | ||
| 130 | } | ||
| 131 | |||
| 132 | sub end_page | ||
| 133 | { | ||
| 134 | # my $self = shift; | ||
| 135 | # my ($context) = @_; | ||
| 136 | |||
| 137 | return 1; | ||
| 138 | } | ||
| 139 | |||
| 140 | 1; | ||
| 141 | __END__ |