Skip to content

Instantly share code, notes, and snippets.

@hexfusion
Created November 11, 2013 14:51
Show Gist options
  • Save hexfusion/7414283 to your computer and use it in GitHub Desktop.
Save hexfusion/7414283 to your computer and use it in GitHub Desktop.
record_is_object.diff
diff --git a/lib/Template/Flute.pm b/lib/Template/Flute.pm
index 816dc90..b52aa5f 100644
--- a/lib/Template/Flute.pm
+++ b/lib/Template/Flute.pm
@@ -3,6 +3,8 @@ package Template::Flute;
use strict;
use warnings;
+use Scalar::Util qw/blessed/;
+
use Template::Flute::Utils;
use Template::Flute::Specification::XML;
use Template::Flute::HTML;
@@ -853,14 +855,26 @@ sub process_template {
sub _replace_record {
my ($self, $container, $type, $lel, $paste_pos, $record, $row_pos) = @_;
- my ($param, $key, $filter, $rep_str, $att_name, $att_spec,
+ my ($param, $key, $filter, $rep_str, $att_name, $att_spec, $record_is_object,
$att_tag_name, $att_tag_spec, %att_tags, $att_val, $class_alt, $elt_handler);
+ $record_is_object = defined blessed $record;
+
# now fill in params
for $param (@{$container->params}) {
- $key = $param->{name};
-
- $rep_str = $record->{$param->{field} || $key};
+ if ($param->{field}) {
+ $key = $param->{field};
+ }
+ else {
+ $key = $param->{name};
+ }
+
+ if ($record_is_object) {
+ $rep_str = $record->$key;
+ }
+ else {
+ $rep_str = $record->{$key};
+ }
if ($param->{increment}) {
$rep_str = $param->{increment}->value();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment