--- trunk/lib/Frey/CouchAPI.pm 2009/04/24 17:41:45 1060 +++ trunk/lib/Frey/CouchAPI.pm 2009/04/24 21:51:03 1061 @@ -23,7 +23,7 @@ use File::Path qw(make_path remove_tree); use Storable; -our $VERSION = '0.2'; +our $VERSION = '0.3'; $VERSION .= " (Frey $Frey::VERSION)" if $Frey::VERSION; our $debug = $Frey::debug || 0; @@ -43,15 +43,12 @@ } our $config = { - path => '/data/webpac2/var/row', + database => { + path => '/data/webpac2/var/row', + name_glob => '/*/*', + } }; -my $p = $config->{path}; -my @all_dbs = map { - s{^\Q$p\E/*}{}; - $_; -} glob "$p/*/*"; - my $regex_dbs = '[a-z][a-z0-9_\$\(\)\+\-/]+'; our $json = {}; @@ -81,7 +78,7 @@ my $url = $tx->req->url->to_string; $url = uri_unescape( $url ); my $method = $tx->req->method; - my $path = $config->{path}; + my $path = $config->{database}->{path}; if ( $url eq '/' ) { $json = { @@ -90,24 +87,27 @@ }; $status = 200; } elsif ( $url eq '/_all_dbs' ) { - $json = [ @all_dbs ]; + $json = [ + map { + s{^\Q$path\E/*}{}; + $_; + } glob $path . $config->{database}->{name_glob} + ]; $status = 200; } elsif ( $url =~ m{^/_config/?(.+)} ) { - $json = { CouchAPI => $config }; + $json = $config; if ( $method eq 'PUT' ) { my $part = $1; - warn "## part $part"; + my $data = data_from_tx( $tx ); + warn "## part $part = $data\n"; - $part =~ s!^!->{'!; $part =~ s!/!'}->{'!; - $part =~ s/$/'}/; - my $data = data_from_tx( $tx ); # poor man's transaction :-) - my $code = "\$json$part = \$data; \$config$part = \$data;"; + my $code = "\$config->{'$part'} = \$data;"; eval $code; if ( $@ ) { warn "ERROR: $code -> $@"; @@ -116,7 +116,7 @@ $status = 200; } -warn "json ",dump( $json ), " config ", dump( $config ); + warn "# config after $code is ",dump( $config ),$/; } elsif ( $method eq 'GET' ) { $status = 200; @@ -355,7 +355,7 @@ sub database_get { my ($db_name) = @_; - my $path = $config->{path}; + my $path = $config->{database}->{path} || die; warn "# collecting docs from $path/$db_name/*\n"; my @docs = glob "$path/$db_name/*"; my $json = {