You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2012/01/21 03:35:22 UTC
[lucy-commits] svn commit: r1234243 - in /incubator/lucy/trunk/clownfish:
perl/lib/Clownfish/CFC.pm perl/lib/Clownfish/CFC.xs src/CFCClass.c
src/CFCPerlPod.c src/CFCPerlPod.h
Author: marvin
Date: Sat Jan 21 02:35:21 2012
New Revision: 1234243
URL: http://svn.apache.org/viewvc?rev=1234243&view=rev
Log:
Improve CFCPerlPod interface.
Give add_method() and add_constructor() sensible Perl bindings and improve
their internal functionality.
Modified:
incubator/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.pm
incubator/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs
incubator/lucy/trunk/clownfish/src/CFCClass.c
incubator/lucy/trunk/clownfish/src/CFCPerlPod.c
incubator/lucy/trunk/clownfish/src/CFCPerlPod.h
Modified: incubator/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.pm?rev=1234243&r1=1234242&r2=1234243&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.pm (original)
+++ incubator/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.pm Sat Jan 21 02:35:21 2012
@@ -693,19 +693,55 @@ BEGIN { XSLoader::load( 'Clownfish::CFC'
push @$constructors, $args{constructor} if $args{constructor};
my $self = _new( $synopsis, $description );
- for (@$methods) {
- if ( ref($_) ) {
- _add_method( $self, $_->{name}, $_->{pod} );
+ for my $meth (@$methods) {
+ if ( ref($meth) ) {
+ $self->add_method(
+ alias => $meth->{alias} || $meth->{name},
+ method => $meth->{method},
+ sample => $meth->{sample},
+ pod => $meth->{pod},
+ );
}
else {
- _add_method( $self, $_, undef );
+ $self->add_method( alias => $meth );
}
}
for my $con (@$constructors) {
- _add_constructor( $self, @{$con}{qw( name pod func sample )} );
+ $self->add_constructor(
+ alias => $con->{alias} || $con->{name},
+ initializer => $con->{initializer} || $con->{func},
+ sample => $con->{sample},
+ pod => $con->{pod},
+ );
}
return $self;
}
+
+ my %add_method_PARAMS = (
+ alias => undef,
+ method => undef,
+ sample => undef,
+ pod => undef,
+ );
+
+ sub add_method {
+ my ( $self, %args ) = @_;
+ verify_args( \%add_method_PARAMS, %args ) or confess $@;
+ _add_method( $self, @args{qw( alias method sample pod )} );
+ }
+
+ my %add_constructor_PARAMS = (
+ alias => undef,
+ initializer => undef,
+ sample => undef,
+ pod => undef,
+ );
+
+ sub add_constructor {
+ my ( $self, %args ) = @_;
+ verify_args( \%add_constructor_PARAMS, %args ) or confess $@;
+ _add_constructor( $self, @args{qw( alias initializer sample pod )} );
+ }
}
{
Modified: incubator/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs?rev=1234243&r1=1234242&r2=1234243&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs (original)
+++ incubator/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs Sat Jan 21 02:35:21 2012
@@ -1954,27 +1954,31 @@ CODE:
OUTPUT: RETVAL
void
-_add_method(self, name, pod_sv)
+_add_method(self, alias, method_sv, sample_sv, pod_sv)
CFCPerlPod *self;
- const char *name;
+ const char *alias;
+ SV *method_sv;
+ SV *sample_sv;
SV *pod_sv;
PPCODE:
- const char *pod = SvPOK(pod_sv) ? SvPVutf8_nolen(pod_sv) : NULL;
- CFCPerlPod_add_method(self, name, pod);
+ const char *method = SvPOK(method_sv) ? SvPVutf8_nolen(method_sv) : NULL;
+ const char *sample = SvPOK(sample_sv) ? SvPVutf8_nolen(sample_sv) : NULL;
+ const char *pod = SvPOK(pod_sv) ? SvPVutf8_nolen(pod_sv) : NULL;
+ CFCPerlPod_add_method(self, alias, method, sample, pod);
void
-_add_constructor(self, name_sv, pod_sv, func_sv, sample_sv)
+_add_constructor(self, alias_sv, init_sv, sample_sv, pod_sv)
CFCPerlPod *self;
- SV *name_sv;
- SV *pod_sv;
- SV *func_sv;
+ SV *alias_sv;
+ SV *init_sv;
SV *sample_sv;
+ SV *pod_sv;
PPCODE:
- const char *name = SvPOK(name_sv) ? SvPVutf8_nolen(name_sv) : NULL;
- const char *pod = SvPOK(pod_sv) ? SvPVutf8_nolen(pod_sv) : NULL;
- const char *func = SvPOK(func_sv) ? SvPVutf8_nolen(func_sv) : NULL;
+ const char *alias = SvPOK(alias_sv) ? SvPVutf8_nolen(alias_sv) : NULL;
+ const char *init = SvPOK(init_sv) ? SvPVutf8_nolen(init_sv) : NULL;
const char *sample = SvPOK(sample_sv) ? SvPVutf8_nolen(sample_sv) : NULL;
- CFCPerlPod_add_constructor(self, name, pod, func, sample);
+ const char *pod = SvPOK(pod_sv) ? SvPVutf8_nolen(pod_sv) : NULL;
+ CFCPerlPod_add_constructor(self, alias, init, sample, pod);
SV*
methods_pod(self, klass)
Modified: incubator/lucy/trunk/clownfish/src/CFCClass.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCClass.c?rev=1234243&r1=1234242&r2=1234243&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCClass.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCClass.c Sat Jan 21 02:35:21 2012
@@ -434,6 +434,10 @@ CFCClass_has_attribute(CFCClass *self, c
static CFCFunction*
S_find_func(CFCFunction **funcs, const char *sym) {
+ if (!sym) {
+ return NULL;
+ }
+
const size_t MAX_LEN = 128;
char lcsym[MAX_LEN + 1];
size_t sym_len = strlen(sym);
Modified: incubator/lucy/trunk/clownfish/src/CFCPerlPod.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCPerlPod.c?rev=1234243&r1=1234242&r2=1234243&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCPerlPod.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCPerlPod.c Sat Jan 21 02:35:21 2012
@@ -34,7 +34,7 @@
#endif
typedef struct NamePod {
- char *name;
+ char *alias;
char *func;
char *sample;
char *pod;
@@ -80,7 +80,7 @@ CFCPerlPod_destroy(CFCPerlPod *self) {
FREEMEM(self->synopsis);
FREEMEM(self->description);
for (size_t i = 0; i < self->num_methods; i++) {
- FREEMEM(self->methods[i].name);
+ FREEMEM(self->methods[i].alias);
FREEMEM(self->methods[i].pod);
FREEMEM(self->methods[i].func);
FREEMEM(self->methods[i].sample);
@@ -90,30 +90,31 @@ CFCPerlPod_destroy(CFCPerlPod *self) {
}
void
-CFCPerlPod_add_method(CFCPerlPod *self, const char *name, const char *pod) {
- CFCUTIL_NULL_CHECK(name);
+CFCPerlPod_add_method(CFCPerlPod *self, const char *alias, const char *method,
+ const char *sample, const char *pod) {
+ CFCUTIL_NULL_CHECK(alias);
self->num_methods++;
size_t size = self->num_methods * sizeof(NamePod);
self->methods = (NamePod*)REALLOCATE(self->methods, size);
NamePod *slot = &self->methods[self->num_methods - 1];
- slot->name = CFCUtil_strdup(name);
+ slot->alias = CFCUtil_strdup(alias);
+ slot->func = method ? CFCUtil_strdup(method) : NULL;
+ slot->sample = CFCUtil_strdup(sample ? sample : "");
slot->pod = pod ? CFCUtil_strdup(pod) : NULL;
- slot->func = NULL;
- slot->sample = NULL;
}
void
-CFCPerlPod_add_constructor(CFCPerlPod *self, const char *name,
- const char *pod, const char *func,
- const char *sample) {
+CFCPerlPod_add_constructor(CFCPerlPod *self, const char *alias,
+ const char *initializer, const char *sample,
+ const char *pod) {
self->num_constructors++;
size_t size = self->num_constructors * sizeof(NamePod);
self->constructors = (NamePod*)REALLOCATE(self->constructors, size);
NamePod *slot = &self->constructors[self->num_constructors - 1];
- slot->name = CFCUtil_strdup(name ? name : "new");
- slot->pod = pod ? CFCUtil_strdup(pod) : NULL;
- slot->func = CFCUtil_strdup(func ? func : "init");
+ slot->alias = CFCUtil_strdup(alias ? alias : "new");
+ slot->func = CFCUtil_strdup(initializer ? initializer : "init");
slot->sample = CFCUtil_strdup(sample ? sample : "");
+ slot->pod = pod ? CFCUtil_strdup(pod) : NULL;
}
const char*
@@ -134,19 +135,24 @@ CFCPerlPod_methods_pod(CFCPerlPod *self,
char *methods_pod = CFCUtil_strdup("");
for (size_t i = 0; i < self->num_methods; i++) {
NamePod meth_spec = self->methods[i];
- CFCMethod *method = CFCClass_method(klass, meth_spec.name);
+ CFCMethod *method = CFCClass_method(klass, meth_spec.func);
+ if (!method) {
+ method = CFCClass_method(klass, meth_spec.alias);
+ }
if (!method) {
CFCUtil_die("Can't find method '%s' in class '%s'",
- meth_spec.name, CFCClass_get_class_name(klass));
+ meth_spec.alias, CFCClass_get_class_name(klass));
}
char *meth_pod;
if (meth_spec.pod) {
meth_pod = CFCPerlPod_perlify_doc_text(self, meth_spec.pod);
}
else {
- char *raw = CFCPerlPod_gen_subroutine_pod(self, (CFCFunction*)method,
- meth_spec.name, klass,
- NULL, class_name, false);
+ char *raw
+ = CFCPerlPod_gen_subroutine_pod(self, (CFCFunction*)method,
+ meth_spec.alias, klass,
+ meth_spec.sample, class_name,
+ false);
meth_pod = CFCPerlPod_perlify_doc_text(self, raw);
FREEMEM(raw);
}
@@ -190,7 +196,7 @@ CFCPerlPod_constructors_pod(CFCPerlPod *
else {
CFCFunction *init_func = CFCClass_function(klass, slot.func);
char *sub_pod
- = CFCPerlPod_gen_subroutine_pod(self, init_func, slot.name, klass,
+ = CFCPerlPod_gen_subroutine_pod(self, init_func, slot.alias, klass,
slot.sample, class_name, true);
char *perlified = CFCPerlPod_perlify_doc_text(self, sub_pod);
pod = CFCUtil_cat(pod, perlified, NULL);
Modified: incubator/lucy/trunk/clownfish/src/CFCPerlPod.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCPerlPod.h?rev=1234243&r1=1234242&r2=1234243&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCPerlPod.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCPerlPod.h Sat Jan 21 02:35:21 2012
@@ -38,13 +38,35 @@ CFCPerlPod_init(CFCPerlPod *self, const
void
CFCPerlPod_destroy(CFCPerlPod *self);
+/** Add pod for a method.
+ *
+ * @param alias The name of the method, spelled as it will be used from
+ * Perl-space.
+ * @param method The name of the method from the Clownfish class. If not
+ * supplied, an attempt will be made to locate the correct method using
+ * <code>alias</code>.
+ * @param sample An optional Perl usage sample.
+ * @param pod Optional verbatim POD, which will override all POD which would
+ * otherwise have been generated.
+ */
void
-CFCPerlPod_add_method(CFCPerlPod *self, const char *name, const char *pod);
+CFCPerlPod_add_method(CFCPerlPod *self, const char *alias, const char *method,
+ const char *sample, const char *pod);
+/** Add pod for a constructor.
+ *
+ * @param alias The name of the constructor, spelled as it will be used from
+ * Perl-space.
+ * @param initializer The name of the initialization routine from the
+ * Clownfish class. Defaults to "init".
+ * @param sample An optional Perl usage sample.
+ * @param pod Optional verbatim POD, which will override all POD which would
+ * otherwise have been generated.
+ */
void
-CFCPerlPod_add_constructor(CFCPerlPod *self, const char *name,
- const char *pod, const char *func,
- const char *sample);
+CFCPerlPod_add_constructor(CFCPerlPod *self, const char *alias,
+ const char *initializer, const char *sample,
+ const char *pod);
char*
CFCPerlPod_methods_pod(CFCPerlPod *self, struct CFCClass *klass);