From b8e182acade7dc6f008d79221f1274fa1e3003dc Mon Sep 17 00:00:00 2001 From: John Darrington Date: Thu, 25 Dec 2008 12:16:35 +0900 Subject: [PATCH] New subroutine PSPP::Dict::get_var_by_name --- perl-module/PSPP.xs | 17 +++++++++++++++++ perl-module/lib/PSPP.pm | 22 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/perl-module/PSPP.xs b/perl-module/PSPP.xs index de5cbf7b..3b3dccef 100644 --- a/perl-module/PSPP.xs +++ b/perl-module/PSPP.xs @@ -273,6 +273,23 @@ CODE: OUTPUT: RETVAL + +struct variable * +pxs_get_var_by_name (dict, name) + struct dictionary *dict + const char *name +INIT: + SV *errstr = get_sv("PSPP::errstr", TRUE); + sv_setpv (errstr, ""); +CODE: + struct variable *var = dict_lookup_var (dict, name); + if ( ! var ) + sv_setpv (errstr, "No such variable."); + RETVAL = var; + OUTPUT: +RETVAL + + MODULE = PSPP PACKAGE = PSPP::Var diff --git a/perl-module/lib/PSPP.pm b/perl-module/lib/PSPP.pm index a000b011..6fbae803 100644 --- a/perl-module/lib/PSPP.pm +++ b/perl-module/lib/PSPP.pm @@ -106,6 +106,28 @@ sub get_var return $var; } +=pod + +=head3 get_var_by_name ($name) + +Returns the variable from the dictionary whose name is C. +If there is no such variable, a null reference will be returned. + +=cut + +sub get_var_by_name +{ + my $dict = shift; + my $name = shift; + my $var = pxs_get_var_by_name ($dict, $name); + + if ( ref $var ) + { + bless ($var, "PSPP::Var"); + } + return $var; +} + package PSPP::Fmt; -- 2.30.2