/[pxelator]/lib/PXElator/store.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /lib/PXElator/store.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 485 - (show annotations)
Sat Jan 23 19:46:19 2010 UTC (14 years, 2 months ago) by dpavlin
File size: 1085 byte(s)
store data in MongoDB

1 package store;
2
3 use warnings;
4 use strict;
5
6 use POSIX;
7 use Time::HiRes qw/time/;
8
9 #use CouchDB;
10
11 use MongoDB;
12
13 my $conn = MongoDB::Connection->new;
14 my $db = $conn->get_database( 'pxelator' );
15 our $audit = $db->get_collection( 'audit' );
16
17
18 sub audit {
19 my $data = pop @_;
20
21 my $url = join(' ', @_);
22 $url =~ s/\s+-\S+//g; # remove command line options
23 $url =~ s/\W+/-/g;
24
25 my $time = time();
26
27 my @caller = caller(0);
28 $caller[3] = (caller(1))[3];
29 $caller[3] =~ s{^.+::}{}; # stip package name from sub
30 $data->{package} = {
31 time => $time,
32 name => $caller[0],
33 line => $caller[2],
34 caller => $caller[3],
35 };
36
37 if ( $ENV{DEBUG} ) {
38
39 my $caller;
40 my $depth = 0;
41 while ( my @c = caller($depth) ) {
42 push @$caller, [ @c ];
43 $depth++;
44 }
45
46 $data->{caller} = $caller;
47
48 }
49
50 # carp 'audit ', dump($data);
51
52 # $time = int($time); # reduce granularity for url
53 $time = strftime("%Y-%m-%d.%H:%M:%S", localtime $time);
54 my $package = $caller[0];
55
56 # CouchDB::_store_audit( "$time.$package.$url" => $data );
57
58 # $data->{_id} = "$time.$package.$url";
59 $audit->insert( $data );
60 }
61
62
63 1;

  ViewVC Help
Powered by ViewVC 1.1.26