]> git.evergreen-ils.org Git - working/Evergreen.git/blob - docs/development/perl_client.pl
Add "Intro to OpenSRF" to development section
[working/Evergreen.git] / docs / development / perl_client.pl
1 #/usr/bin/perl
2 use strict;
3 use OpenSRF::AppSession;
4 use OpenSRF::System;
5 use Data::Dumper;
6
7 OpenSRF::System->bootstrap_client(config_file => '/openils/conf/opensrf_core.xml');
8
9 my $session = OpenSRF::AppSession->create("opensrf.simple-text");
10
11 print "substring: Accepts a string and a number as input, returns a string\n";
12 my $request = $session->request("opensrf.simple-text.substring", "foobar", 3);
13
14 my $response;
15 while ($response = $request->recv()) {
16     print "Substring: " . $response->content . "\n\n";
17 }
18
19 print "split: Accepts two strings as input, returns an array of strings\n";
20 $request = $session->request("opensrf.simple-text.split", "This is a test", " ")->gather();
21 my $output = "Split: [";
22 foreach my $element (@$request) {
23     $output .= "$element, ";
24 }
25 $output =~ s/, $/]/;
26 print $output . "\n\n";
27
28 print "statistics: Accepts an array of strings as input, returns a hash\n";
29 my @many_strings = [
30     "First I think I'll have breakfast",
31     "Then I think that lunch would be nice",
32     "And then seventy desserts to finish off the day"
33 ];
34
35 $request = $session->request("opensrf.simple-text.statistics", @many_strings)->gather();
36 print "Length: " . $request->{'length'} . "\n";
37 print "Word count: " . $request->{'word_count'} . "\n";
38
39 $session->disconnect();
40