Couch-DB

 view release on metacpan or  search on metacpan

bin/reference-table  view on Meta::CPAN

#!/usr/bin/env perl
use warnings;
use strict;

use LWP::UserAgent    ();
use HTML::TreeBuilder ();
use File::Slurper     qw(read_text read_lines write_text);
use URI::Escape       qw(uri_escape);
use Getopt::Long      qw(GetOptions);
use HTML::Entities    qw(encode_entities);

use Data::Dumper;
$Data::Dumper::Indent = 1;

my $couchdb_api   = 'https://docs.couchdb.org/en/stable';
my $couchdb_index = "$couchdb_api/http-routingtable.html";
my $couchdb_cache = '/tmp/couch-cache';
my $metacpan      = 'https://metacpan.org/dist/Couch-DB/view/';

GetOptions
	'refresh|r!' => \(my $refresh = 0),
	;

my %index;         # from the couchdb website
my %impls_by_call; # from this module
my %impls_by_use;  # from this module

my %http_order;
$http_order{$_} = keys %http_order for qw/GET POST PUT COPY DELETE/;

####
###### parse the couchdb api index
####

sub fill_index()
{
	my $routing;
	if($refresh || ! -r $couchdb_cache || -M $couchdb_cache > 14)
	{	print "Loading new routing table from couchdb.org\n";
		my $ua = LWP::UserAgent->new;
		my $overview = $ua->get($couchdb_index);
		$routing     = $overview->decoded_content;
		write_text $couchdb_cache, $routing;
	}
	else
	{	$routing     = read_text $couchdb_cache;
	}
	
	my $tree = HTML::TreeBuilder->new_from_content($routing);
	#my $table = $tree->elementify->find('table');
	foreach my $tr ($tree->elementify->find('table')->find('tr'))
	{	my (undef, $which, $what) = $tr->find('td');
		my ($a)  = $which->find('a') or next;
		my $href = $a->attr('href');
		my $call = $a->find_by_attribute(class => 'xref')->content->[0];

		# Mistake in 3.3.3 docs
		$call    = 'POST /{db}/_design/{ddoc}/_update/{func}/{docid}'
			if $call eq 'PUT /{db}/_design/{ddoc}/_update/{func}/{docid}';

		my ($http_method, $endpoint) = split " ", $call, 2;
		my $descr = $what->as_text;
	
		my %def    = (
			call        => $call,
			http_method => $http_method,
			endpoint    => $endpoint,
			doclink     => "$couchdb_api/$href",
			descr       => $descr,
		);
		$index{$call} = \%def;
	}

	# These are only described in notes in 3.3.3
	foreach my $endpoint ('/{db}/_local_docs/queries', '/{db}/_design_docs/queries')
	{	my %def = %{$index{'POST /{db}/_all_docs/queries'}};
		$def{call}     = "POST $endpoint";
		$def{endpoint} = $endpoint;
		$def{descr}    = '';
		$index{"POST $endpoint"} = \%def;
	}

	warn "Found ", scalar keys %index, " calls in the API docs\n";

}

####
###### parse the docs from implementation
####

my @modules = (
	{ file => 'lib/Couch/DB.pm',			base => '$couch' },
	{ file => 'lib/Couch/DB/Client.pm',		base => '$client' },
	{ file => 'lib/Couch/DB/Cluster.pm',	base => '$cluster' },
	{ file => 'lib/Couch/DB/Database.pm',	base => '$db' },
	{ file => 'lib/Couch/DB/Document.pm',	base => '$doc' },
 	{ file => 'lib/Couch/DB/Design.pm',		base => '$ddoc' },
	{ file => 'lib/Couch/DB/Node.pm',		base => '$node' },
);

sub fill_impls_by_call()
{



( run in 1.288 second using v1.01-cache-2.11-cpan-39bf76dae61 )