/[couchdb]/design/design-couch.pl
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 /design/design-couch.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 29 - (show annotations)
Sun Apr 26 19:45:11 2009 UTC (15 years ago) by dpavlin
File MIME type: text/plain
File size: 1149 byte(s)
Helper to dump CouchDB _design document into filesystem

It tries to do same things as couchapp does if it can
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use LWP::UserAgent;
7 use JSON;
8 use Data::Dump qw/dump/;
9 use File::Path qw/mkpath/;
10 use File::Slurp qw//;
11
12 # design-couch.pl
13 #
14 # 04/26/09 21:12:28 CEST Dobrica Pavlinusic <dpavlin@rot13.org>
15
16 my $ua = LWP::UserAgent->new;
17
18 my $url = 'http://llin.lan:5984/blog/_design/sofa';
19
20 my $response = $ua->get( $url );
21
22 die $response->status_line if $response->is_error;
23
24 my $design = from_json $response->decoded_content;
25
26 my $path;
27
28 sub write_file {
29 my ( $path, $content ) = @_;
30 if ( $path =~ m{/} ) {
31 my $dir = $path;
32 $dir =~ s{/[^/]+$}{};
33 mkpath $dir if ! -e $dir;
34 warn "# dir $dir";
35 }
36 warn "# write_file $path $content";
37 File::Slurp::write_file $path, $content;
38 }
39
40 sub unroll {
41 my ( $tree, $path ) = @_;
42
43 my $ref = ref $tree;
44 if ( $ref eq 'HASH' ) {
45 unroll( $tree->{$_}, "$path/$_" ) foreach ( keys %$tree );
46 } elsif ( $ref eq '' ) {
47 $path =~ s{^/+}{};
48
49 my $ext = '';
50
51 if ( $tree =~ m{^\s*function}i ) {
52 $ext = '.js';
53 } elsif ( $tree =~ m{<\w+>} ) {
54 $ext = '.html';
55 }
56
57 write_file $path . $ext , $tree;
58 print "$path ", -s $path, " bytes\n";
59 }
60
61 }
62
63 unroll( $design, '/' );
64

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26