File Coverage

blib/lib/WWW/betfair/Template.pm
Criterion Covered Total %
statement 6 28 21.4
branch 0 10 0.0
condition n/a
subroutine 2 4 50.0
pod 2 2 100.0
total 10 44 22.7


line stmt bran cond sub pod time code
1             package WWW::betfair::Template;
2 1     1   8 use strict;
  1         1  
  1         23  
3 1     1   3 use warnings;
  1         1  
  1         198  
4              
5             =head2 populate
6              
7             Returns the XML message required for the betfair API
8              
9             =cut
10              
11             sub populate {
12 0     0 1   my ($uri, $action, $params) = @_;
13              
14             #handle getAccountStatement betfair syntax exception
15 0 0         my $req = $action eq 'getAccountStatement' ? 'req' : 'request';
16            
17 0           my $templateHeader = qq~<$action xmlns="$uri"><$req>~;
18              
19 0           my $templateBody = '';
20 0           $templateBody .= markup_data(undef,$params);
21 0           my $templateFooter = "";
22 0           return $templateHeader . $templateBody . $templateFooter;
23             }
24              
25             =head2 markup_data
26              
27             Recursive tagging subroutine for a Perl data structure
28              
29             =cut
30              
31             sub markup_data {
32 0     0 1   my ($key, $data) = @_;
33 0           my $string = '';
34 0 0         if (ref($data) eq 'HASH') {
    0          
35 0 0         $string .= "<$key>" if $key;
36 0           foreach (keys %{$data}) {
  0            
37 0           $string .= markup_data($_, $data->{$_});
38             }
39 0 0         $string .= "" if $key;
40 0           return $string;
41             }
42             elsif (ref($data) eq 'ARRAY') {
43 0           my $string = '';
44 0           foreach (@{$data}) {
  0            
45 0           $string .= markup_data($key, $_);
46             }
47 0           return $string;
48             }
49             else {
50 0           return "<$key>$data";
51             }
52             }
53             1;