extracted to_hstore
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 23 May 2011 18:44:09 +0000 (20:44 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 23 May 2011 18:44:17 +0000 (20:44 +0200)
lib/APKPM/DSLAM.pm
lib/APKPM/Gearman.pm

index ab52ad4..3a99340 100644 (file)
@@ -12,8 +12,6 @@ with 'APKPM::Gearman::Client';
 use H1::ZTEDSLAM;
 use H1::ZTEMSAN;
 
-use Data::Dumper;
-
 sub prefix { 'DSLAM_' }
 
 sub process_name {
@@ -56,19 +54,12 @@ sub search : Job : Encode(e_json_encode) {
        eval { $hash = $module->hash( $crm->{IP_UREDAJA}, $crm->{SHELF_SLOT_PORT} ) };
        return { error => $@ } if $@;
 
-       warn "# hash ",dump $hash;
-       local $Data::Dumper::Useqq = 1; # double quote for PostgreSQL
-       my $h = Dumper($hash);
-       $h =~ s/\s+/ /gs;
-       $h =~ s/^\$\w+\s*=\s*{\s*//s;
-       $h =~ s/\s*}\s*;\s*$//s;
-
        $self->do_background_json( 'Store_insert', {
                _table => 'dslam_h',
                ip => $crm->{IP_MANAGEMENT}, # FIXME IP_UREDAJA ?
                username => $crm->{USERNAME},
                timestamp => $time,
-               h => $h,
+               h => $self->to_hstore($hash),
        });
 
        return $hash;
index 8a6ef80..31dbb94 100644 (file)
@@ -8,6 +8,8 @@ use JSON::XS;
 use DateTime;
 use DateTime::Format::Pg;
 
+use Data::Dumper;
+
 sub e_json {
        my ( $self, $result ) = @_;
        warn "# e_json ", dump $result;
@@ -31,4 +33,17 @@ sub datetime_now {
        return DateTime::Format::Pg->format_datetime( DateTime->now );
 }
 
+sub to_hstore {
+       my ($self,$hash) = @_;
+
+       warn "# hash ",dump $hash;
+       local $Data::Dumper::Useqq = 1; # double quote for PostgreSQL
+       my $h = Dumper($hash);
+       $h =~ s/\s+/ /gs;
+       $h =~ s/^\$\w+\s*=\s*{\s*//s;
+       $h =~ s/\s*}\s*;\s*$//s;
+
+       return $h;
+}
+
 1;