Sfoglia il codice sorgente

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

Alois Mahdal 12 anni fa
parent
commit
1b3d293d00
1 ha cambiato i file con 21 aggiunte e 0 eliminazioni
  1. 21
    0
      lib/htlogr.pm

+ 21
- 0
lib/htlogr.pm Vedi File

41
     my $msg     = shift;
41
     my $msg     = shift;
42
     my $tag     = shift;
42
     my $tag     = shift;
43
     my $i       = shift;
43
     my $i       = shift;
44
+
44
     my $uri;
45
     my $uri;
45
     $uri .= $self->{path};
46
     $uri .= $self->{path};
46
     $uri .= "?msg=" . uri_escape($msg);
47
     $uri .= "?msg=" . uri_escape($msg);
50
     return $self->{http}->body();
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
 1;
74
 1;