Browse Source

Added htogr::data(), able render and log simple hash data structure (stats etc.)

Alois Mahdal 12 years ago
parent
commit
1b3d293d00
1 changed files with 21 additions and 0 deletions
  1. 21
    0
      lib/htlogr.pm

+ 21
- 0
lib/htlogr.pm View File

@@ -41,6 +41,7 @@ sub log {
41 41
     my $msg     = shift;
42 42
     my $tag     = shift;
43 43
     my $i       = shift;
44
+
44 45
     my $uri;
45 46
     $uri .= $self->{path};
46 47
     $uri .= "?msg=" . uri_escape($msg);
@@ -50,4 +51,24 @@ sub log {
50 51
     return $self->{http}->body();
51 52
 }
52 53
 
54
+sub data {
55
+    my $self    = shift;
56
+    my $data    = shift;
57
+    my $tag     = shift;
58
+    my $i       = shift;
59
+
60
+    #TODO: Make them global
61
+    my $DIV_FIELD =";";
62
+    my $DIV_VALUE ="=";
63
+
64
+    carp("data must be a hash reference" unless ref $data == 'HASH');
65
+
66
+    my @fields;
67
+    foreach (keys %$data) {
68
+        push @fields, join $DIV_VALUE, $_, $data->$_;
69
+    }
70
+
71
+    $self->log( (join $DIV_FIELD, @fields), $tag, $i );
72
+}
73
+
53 74
 1;