Merge branch 'devel' of h1dev:/srv/APKPM/
[APKPM.git] / lib / APKPM / Gearman.pm
index 8a6ef80..3c0cc1c 100644 (file)
@@ -8,9 +8,12 @@ use JSON::XS;
 use DateTime;
 use DateTime::Format::Pg;
 
+use Data::Dumper;
+
 sub e_json {
        my ( $self, $result ) = @_;
        warn "# e_json ", dump $result;
+       return $result unless ref $result; # FIXME report error?
        return JSON::XS::encode_json($result);
 }
 
@@ -31,4 +34,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;