Browse Source

Allow passing subroutine/function instead of i or tag.

If callable is passed, it will be called (without arguments) and
the value will be used instead.
Alois Mahdal 11 years ago
parent
commit
fbdde0a4b5
2 changed files with 14 additions and 1 deletions
  1. 3
    0
      lib/htlogr.pm
  2. 11
    1
      lib/htlogr.py

+ 3
- 0
lib/htlogr.pm View File

42
     my $tag     = shift;
42
     my $tag     = shift;
43
     my $i       = shift;
43
     my $i       = shift;
44
 
44
 
45
+    $tag = &{$tag}()    if ref($tag) eq 'CODE';
46
+    $i = &{$i}()        if ref($i) eq 'CODE';
47
+
45
     my $uri;
48
     my $uri;
46
     $uri .= $self->{path};
49
     $uri .= $self->{path};
47
     $uri .= "?msg=" . uri_escape($msg);
50
     $uri .= "?msg=" . uri_escape($msg);

+ 11
- 1
lib/htlogr.py View File

55
         return self.DIV_FIELD.join(fields)
55
         return self.DIV_FIELD.join(fields)
56
 
56
 
57
     def log(self, msg, tag=None, i=None):
57
     def log(self, msg, tag=None, i=None):
58
-        params = {"msg": msg, "tag": tag, "i": i}
58
+        params = {"msg": msg}
59
+
60
+        try:
61
+            params["tag"] = tag()
62
+        except TypeError:
63
+            params["tag"] = tag
64
+        try:
65
+            params["i"] = i()
66
+        except TypeError:
67
+            params["i"] = i
68
+
59
         pq = "%s?%s" % (self.parsed_url.path, self._zipup_params(params))
69
         pq = "%s?%s" % (self.parsed_url.path, self._zipup_params(params))
60
         self.conn.request("GET", pq)
70
         self.conn.request("GET", pq)
61
         self.last_error = None
71
         self.last_error = None