[OPEN-ILS-DEV] OpenSRF API Question
Mike Rylander
mrylander at gmail.com
Sat May 10 08:56:55 EDT 2008
On Fri, May 9, 2008 at 2:01 PM, Doug Kyle <dkyle at grpl.org> wrote:
> I'm working on a small utility program that will pull up patron info. It's
> currently set up as a cgi script:
> #!/usr/bin/perl
> use CGI qw(:standard);
> require '/usr/ports/Evergreen/Open-ILS/src/support-scripts/oils_header.pl';
> my $bcode = param('barcode') || '0';
> my $conf = '/openils/conf/opensrf_core.xml';
> print header;
> if ($bcode) {
> osrf_connect($conf);
> my $authtok = oils_login('<user>','<passwd>');
> $u = simplereq( ACTOR(),
> 'open-ils.actor.user.fleshed.retrieve_by_barcode', $authtok, $bcode);
> print Dumper($u);
> } else { print "Give me a barcode" }
>
> $u expands like so:
> DB<20> x $u
> 0 Fieldmapper::actor::user=ARRAY(0x209af20)
> 0 undef
> 1 undef
> 2 undef
> 3 ARRAY(0x2099830)
> 0 Fieldmapper::actor::user_address=ARRAY(0x20996a0)
> 0 undef
> 1 undef
> 2 undef
> 3 'MAILING'
> 4 'Grand Rapids'
> 5 'USA'
> 6 'Kent'
> 7 2
> 8 44918
> 9 'MI'
> 10 '3051 Hearland Ave'
> 11 undef
> 12 3
> 13 't'
> 14 'f'
> 4 ARRAY(0x2099bf0)
> 0 Fieldmapper::actor::card=ARRAY(0x20999f0)
> 0 undef
> 1 undef
> 2 undef
> 3 't'
> 4 21298004609999
> 5 3
> 6 3
> 5 undef
> etc and so on.........
>
> I'm wondering if there are existing methods for taking structures such as $u
> and mapping the appropriate names to the various array items? and maybe
> doing some pretty output formatting? I'm just starting to look, but thought
> I might save some time by asking.
>
>
Actually, because you have your config file in the default location
(not required, but makes it simpler) and you're require'ing the
oils_header.pl example, you already have access to the full
Fieldmapper API, which happens to be what you're looking for.
You'll notice that the arrays there are blessed into Perl packages
like Fieldmapper::actor::card. That package defines accessor/mutator
methods for each field, on the actor.card table in this particular
case, as well as some methods that return some class-level information
and some administrative and state-maintenance fields. You can see
what accessors are defined by looking for the class in the Evergreen
Fieldmapper IDL xml file, which you'll find at
/openils/conf/fm_IDL.xml . To find the class in question, you'll
actually look an oils_obj:fieldmapper attribute containing the part of
the Perl package name after 'Fieldmapper::'.
That IDL file defines how Evergreen apps written in any supported
programming language communicate with one another and interpret data.
It's also used to generate a great many interfaces (programmatic and
user interfaced) in Evergreen.
--
Mike Rylander
| VP, Research and Design
| Equinox Software, Inc. / The Evergreen Experts
| phone: 1-877-OPEN-ILS (673-6457)
| email: miker at esilibrary.com
| web: http://www.esilibrary.com
More information about the Open-ils-dev
mailing list