1 % foreach my $row ( @$rows ) {
3 % if (&{$beginrow}($row)){
4 <% &{$beginrow}($row) %>
7 % foreach my $i ( 0 .. scalar( @{$opt{'fields'}} ) - 1 ) {
8 % my $field = $opt{'fields'}->[$i];
10 % if ( ref($field) eq 'CODE' ) {
11 % $value = &{$field}($row);
12 % $value = '(N/A)' #unimplemented
13 % if ref($value) eq 'ARRAY';
15 % $value = $row->$field();
17 % next unless ($value || !$opt{xml_omit_empty});
19 <% &{$beginfield}($row, $i) %><% $value |h %><% &{$endfield}($row, $i) %>
23 % if (&{$endrow}($row)) {
24 <% &{$endrow}($row) %>
31 my $header = $args{'header'};
32 my $rows = $args{'rows'};
33 my %opt = %{ $args{'opt'} };
35 my $filename = $opt{'filename'} ||
36 ($opt{'name'} || PL($opt{'name_singular'}) . 'xml');
38 http_header('Content-Type' => 'application/XML' ); # So saith RFC 4180
39 http_header('Content-Disposition' => 'attachment;filename="'.$filename.'"');
41 unless ( $opt{'fields'} ) {
42 foreach my $i ( 0 .. ( $#{ @$rows[0] } ) ) {
43 $opt{'fields'}->[$i] = sub { my $row = shift; $row->[$i]; };
47 my $beginrow = sub { return ''; };
48 my $endrow = sub { return ''; };
49 if ($opt{xml_row_element}) {
50 $beginrow = sub { my ($row, $index) = @_;
52 if ( ref($opt{xml_row_element}) eq 'CODE' ) {
53 $value = &{$opt{xml_row_element}}($row);
55 $value = $opt{xml_row_element};
59 $endrow = sub { my ($row, $index) = @_;
61 if ( ref($opt{xml_row_element}) eq 'CODE' ) {
62 $value = &{$opt{xml_row_element}}($row);
64 $value = $opt{xml_row_element};
69 my $beginfield = sub { my ($row, $index) = @_;
71 if ( ref($opt{xml_elements}->[$index]) eq 'CODE' ) {
72 $value = &{$opt{xml_elements}->[$index]}($row);
74 $value = $opt{xml_elements}->[$index];
78 my $endfield = sub { my ($row, $index) = @_;
80 if ( ref($opt{xml_elements}->[$index]) eq 'CODE' ) {
81 $value = &{$opt{xml_elements}->[$index]}($row);
83 $value = $opt{xml_elements}->[$index];
88 $beginfield = sub { return ''; } if $opt{no_field_elements}; #hmm
89 $endfield = sub { return ''; } if $opt{no_field_elements}; #hmm