OSSP CVS Repository

ossp - Difference in ossp-pkg/cfg/perl/cfg.pm versions 1.1 and 1.2
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/cfg/perl/cfg.pm 1.1 -> 1.2

--- cfg.pm       2004/11/14 18:38:53     1.1
+++ cfg.pm       2004/11/16 19:31:35     1.2
@@ -134,11 +134,10 @@
     my $self = {};
     bless ($self, $class);
     $self->{-cfg} = undef;
-    $self->{-rc}   = $self->CFG_OK;
+    $self->{-rc}  = $self->CFG_OK;
     my $rc = cfg_create($self->{-cfg});
     if ($rc != $self->CFG_OK) {
-        croak(sprintf("OSSP::cfg::new: cfg_create: %s (%d)", cfg_error($rc), $rc));
-        return undef;
+        croak(sprintf("OSSP::cfg::new: cfg_create: %s (%d)", $self->error($rc), $rc));
     }
     return $self;
 }
@@ -148,27 +147,65 @@
     my ($self) = @_;
     $self->{-rc} = cfg_destroy($self->{-cfg}) if (defined($self->{-cfg}));
     if ($self->{-rc} != $self->CFG_OK) {
-        carp(sprintf("OSSP::cfg::DESTROY: cfg_destroy: %s (%d)", cfg_error($self->{-rc}), $self->{-rc}));
+        carp(sprintf("OSSP::cfg::DESTROY: cfg_destroy: %s (%d)", $self->error($self->{-rc}), $self->{-rc}));
         return;
     }
     $self->{-cfg} = undef;
-    $self->{-rc}   = undef;
+    $self->{-rc}  = undef;
     return;
 }
 
-sub FIXME ($$) {
-    my ($self, $name) = @_;
-    $self->{-rc} = cfg_load($self->{-cfg}, $name);
-    return ($self->{-rc} == $self->CFG_OK);
+sub import {
+    #   ATTENTION: The OSSP cfg API function "import" conflicts with
+    #   the standardized "import" method the Perl world expects from
+    #   their modules. In order to keep the Perl binding consist
+    #   with the C API, we solve the conflict under run-time by
+    #   distinguishing between the two types of "import" calls.
+    if (defined($_[0]) and ref($_[0]) =~ m/^OSSP::uuid/) {
+        #   the regular OSSP::cfg "import" method
+        my ($self, $node, $fmt, $in) = @_;
+        $self->{-rc} = cfg_import($self->{-cfg}, $node, $fmt, $in, length($in));
+        return ($self->{-rc} == $self->CFG_OK);
+    }
+    else {
+        #   the special Perl "import" method
+        #   (usually inherited from the Exporter)
+        no strict "refs";
+        return OSSP::cfg->export_to_level(1, @_);
+    }
+}
+
+sub export {
+    #   ATTENTION: The OSSP cfg API function "export" conflicts with
+    #   the standardized "export" method the Perl world expects from
+    #   their modules. In order to keep the Perl binding consist
+    #   with the C API, we solve the conflict under run-time by
+    #   distinguishing between the two types of "export" calls.
+    if (defined($_[0]) and ref($_[0]) =~ m/^OSSP::uuid/) {
+        #   the regular OSSP::cfg "export" method
+        my ($self, $node, $fmt) = @_;
+        my $out;
+        $self->{-rc} = cfg_import($self->{-cfg}, $node, $fmt, $out, 0);
+        return ($self->{-rc} == $self->CFG_OK ? $out : undef);
+    }
+    else {
+        #   the special Perl "export" method
+        #   (usually inherited from the Exporter)
+        return Exporter::export(@_);
+    }
 }
 
 sub error ($;$) {
     my ($self, $rc) = @_;
     $rc = $self->{-rc} if (not defined($rc));
-    return wantarray ? (cfg_error($rc), $rc) : cfg_error($rc);
+    my $error;
+    if (cfg_error($self->{-cfg}, $rc, $error) != $self->CFG_OK) {
+        croak("OSSP::cfg::error: cfg_error: INTERNAL ERROR");
+    }
+    return wantarray ? ($error, $rc) : $error;
 }
 
-sub version (;$) {
+sub version () {
     my ($self) = @_;
     return cfg_version();
 }

CVSTrac 2.0.1