lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [17/19] lucy-clownfish git commit: Perl bindings for Clownfish::Boolean
Date Fri, 20 Nov 2015 14:05:38 GMT
Perl bindings for Clownfish::Boolean


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/49093b3f
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/49093b3f
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/49093b3f

Branch: refs/heads/master
Commit: 49093b3f2c164e370135921f004bf0ac46f5bcf8
Parents: 9465b1b
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Sun Nov 15 16:53:17 2015 +0100
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Tue Nov 17 19:08:43 2015 +0100

----------------------------------------------------------------------
 .../perl/buildlib/Clownfish/Build/Binding.pm    | 53 ++++++++++++++++++++
 runtime/perl/lib/Clownfish.pm                   | 10 ++++
 runtime/perl/lib/Clownfish/Boolean.pm           | 25 +++++++++
 3 files changed, 88 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/49093b3f/runtime/perl/buildlib/Clownfish/Build/Binding.pm
----------------------------------------------------------------------
diff --git a/runtime/perl/buildlib/Clownfish/Build/Binding.pm b/runtime/perl/buildlib/Clownfish/Build/Binding.pm
index cfca479..d2a99fa 100644
--- a/runtime/perl/buildlib/Clownfish/Build/Binding.pm
+++ b/runtime/perl/buildlib/Clownfish/Build/Binding.pm
@@ -25,6 +25,7 @@ sub bind_all {
     $class->bind_test;
     $class->bind_test_alias_obj;
     $class->bind_blob;
+    $class->bind_boolean;
     $class->bind_bytebuf;
     $class->bind_charbuf;
     $class->bind_string;
@@ -144,6 +145,58 @@ END_XS_CODE
     Clownfish::CFC::Binding::Perl::Class->register($binding);
 }
 
+sub bind_boolean {
+    my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
+    my $synopsis = <<'END_SYNOPSIS';
+    use Clownfish::Boolean qw( $true_singleton $false_singleton );
+
+    my $bool = Clownfish::Boolean->singleton($truth_value);
+    my $truth_value = $bool->get_value;
+
+    if ($bool->equals($true_singleton)) {
+        print "true\n";
+    }
+END_SYNOPSIS
+    my $description = <<'END_DESCRIPTION';
+There are only two singleton instances of this class: `$true_singleton` and
+`$false_singleton` which are exported on demand.
+END_DESCRIPTION
+    my $constructor = <<'END_CONSTRUCTOR';
+=head2 singleton(truth_value)
+
+    my $bool = Clownfish::Boolean->singleton($truth_value);
+
+Return a Boolean singleton representing either true or false depending
+on the supplied truth value.
+END_CONSTRUCTOR
+    $pod_spec->set_synopsis($synopsis);
+    $pod_spec->set_description($description);
+    $pod_spec->add_constructor( alias => 'new', pod => $constructor );
+
+    my $xs_code = <<'END_XS_CODE';
+MODULE = Clownfish   PACKAGE = Clownfish::Boolean
+
+SV*
+singleton(either_sv, value)
+    SV      *either_sv;
+    bool     value;
+CODE:
+{
+    RETVAL = CFISH_OBJ_TO_SV(cfish_Bool_singleton(value));
+}
+OUTPUT: RETVAL
+END_XS_CODE
+
+    my $binding = Clownfish::CFC::Binding::Perl::Class->new(
+        parcel     => "Clownfish",
+        class_name => "Clownfish::Boolean",
+    );
+    $binding->set_pod_spec($pod_spec);
+    $binding->append_xs($xs_code);
+
+    Clownfish::CFC::Binding::Perl::Class->register($binding);
+}
+
 sub bind_bytebuf {
     my $xs_code = <<'END_XS_CODE';
 MODULE = Clownfish     PACKAGE = Clownfish::ByteBuf

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/49093b3f/runtime/perl/lib/Clownfish.pm
----------------------------------------------------------------------
diff --git a/runtime/perl/lib/Clownfish.pm b/runtime/perl/lib/Clownfish.pm
index 9a8f03d..840bcbd 100644
--- a/runtime/perl/lib/Clownfish.pm
+++ b/runtime/perl/lib/Clownfish.pm
@@ -168,6 +168,16 @@ sub error {$Clownfish::Err::error}
     sub get_error {$error}
 }
 
+{
+    package Clownfish::Boolean;
+    our $VERSION = '0.004000';
+    $VERSION = eval $VERSION;
+    use Exporter 'import';
+    our @EXPORT_OK = qw( $true_singleton $false_singleton );
+    our $true_singleton  = Clownfish::Boolean->singleton(1);
+    our $false_singleton = Clownfish::Boolean->singleton(0);
+}
+
 1;
 
 __END__

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/49093b3f/runtime/perl/lib/Clownfish/Boolean.pm
----------------------------------------------------------------------
diff --git a/runtime/perl/lib/Clownfish/Boolean.pm b/runtime/perl/lib/Clownfish/Boolean.pm
new file mode 100644
index 0000000..75452cb
--- /dev/null
+++ b/runtime/perl/lib/Clownfish/Boolean.pm
@@ -0,0 +1,25 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+package Clownfish::Boolean;
+use Clownfish;
+our $VERSION = '0.004000';
+$VERSION = eval $VERSION;
+
+1;
+
+__END__
+
+


Mime
View raw message