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,6 +42,9 @@ sub log {
42 42
     my $tag     = shift;
43 43
     my $i       = shift;
44 44
 
45
+    $tag = &{$tag}()    if ref($tag) eq 'CODE';
46
+    $i = &{$i}()        if ref($i) eq 'CODE';
47
+
45 48
     my $uri;
46 49
     $uri .= $self->{path};
47 50
     $uri .= "?msg=" . uri_escape($msg);

+ 11
- 1
lib/htlogr.py View File

@@ -55,7 +55,17 @@ class Htlogr:
55 55
         return self.DIV_FIELD.join(fields)
56 56
 
57 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 69
         pq = "%s?%s" % (self.parsed_url.path, self._zipup_params(params))
60 70
         self.conn.request("GET", pq)
61 71
         self.last_error = None