1 components in perl and soap::lite team "messengers" larry mcknight, md davis bu, md pete...

Post on 16-Dec-2015

213 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

1

Components in Perland SOAP::Lite

Team "Messengers"

Larry McKnight, MDDavis Bu, MDPete Stetson, MDMaryam Kamvar

2

Table of Contents:

Project OverviewProject DemoPerl, SOAP::Lite and Components

3

Context: PalmCIS

Project and Application.Project goal is to reduce medical errors. Improving communication (whiteboard) Timely access to patient information.

PalmCIS (the app) a wireless handheld version of the CIS.

Timely access to domain knowledge (Infobuttons).

4

Communication Example:

Nurse wants orders renewed. Nurse identifies the Intern for her patient. Nurse finds the pager number for the Intern. Nurse pages intern, waits for response. Intern interrupts his current activities to

answer page. Intern must remember task (sign orders) Intern return to previous task.

Inefficient, error prone.

5

Project:A Virtual Whiteboard

Problem: Team structure changes rapidly. Identifying and contacting providers is difficult. Problem: Interruptive work environments make errors more likely.Problem: Patients are very concerned about who looks at their data.

Solution: new system. Patient centered, asynchronous, role based (like a whiteboard).

6

Legacy: WebCIS

Web based Clinical Information System CGI based (written in C). AIX Server

farm. Patient data on mainframe. Restricted

access thru UNIX sockets (DAMs). Provider Authentication data through

LDAP server. C and Perl socket drivers available. No EJB, CORBA, or .NET

7

WebCIS

8

New Problem

We would like to take advantage of principles in this class – XP, Components, etc.We want to use Perl. Legacy Perl drivers. Convincing the system admin to install EJB,

CORBA or .NET to run the project would kill it.

Solution: Use Perl as a component model.

9

Is Perl a Component Model?

Intro to PerlPerl Objects and ModulesSOAP::LiteComponent Model definitions and satisfaction with Perl

Hold questions until end

10

Intro to Perl

In the beginning: UNIX, C, sed, awk.1986 – Larry Wall Practical Extraction and Report Language Pathologically Eclectic Rubbish Lister "So lazy he created a new computer language“

V1, 12/87 Released to Usenet V4, 3/91 The Camel book. V5, 10/94 “Everything else” - Objects, Modules. V5.6, 3/2000 V5.8, 7/2002

Today: widespread use, cgi scripts, CPAN.

11

Why Perl?

Faster development time. ~1/3 – 2/3 as much code. CPAN Common things are easy, hard things are

possible.

Most things are (or can be represented as) text. Perl has excellent string handling.Perl is and (according to Larry Wall, will always be) free. Perl is fun.

12

Common Myths about Perl

Myth:Easy to learn; Fact:Easy to use. Goal has always been power over learning. Lots of quirks, Easier ways.

Myth:Slow; Fact: Mostly Fast. C bindings, Profiling. Use of appropriate data structures. Mod_perl. Don't use it to develop a CAD app or Micro-

kernel.

13

Perl Myths continued…

Myth:Insecure; Fact: Mostly Secure Taints, warnings, use safe Security by design, not obscurity

Myth:Not scalable; Fact: Very scalable The defining problem. The best inter-platform, inter-language support I

know of. It also scales down.

Myth:Un-maintainable; Fact: It Depends “A very high-level language” Perl lets you get away with stuff.

14

Why ! Perl?

Your boss/customer wants it done in some other language.Your problem has lots of numbers in it.You need a GUI.You don't know Perl. You despise the command prompt.You don't want others to see your code.

15

Perl: Data Types

Scalarsmy $null_val=""; my $count++; my $name="Larry";my $string=$name.$count; #string is “Larry1”

Arrays, Lists my @a=();my @stooges=qw(Larry Moe Curley);

Hashesmy %treatment=(diabetes=>"insulin");my $medicine=$treatment{$disease};

16

Perl: Numbers

Type automatically set to int or floats depending on context.12345 Integer -54321 Negative integer 12345.67 Floating point 6.02E23 Scientific notation 0xffff Hexadecimal 0377 Octal 4_294_967_296 Underline for legibility

Override with int or hex functions

17

Perl: Type conversion

Hashes can be arrays%fruit=('apples',3,'oranges',6);

print $fruit{apples}; #prints 3

All arrays have scalar contexts$a=(2,4,6,8); #a is 8

$b=%c; #b is the number of items in c

($sec, $min, $hour, …)=localtime;

$now=localtime; #$now is like "Fri Aug 18,…)

18

Perl: Subroutines

Arguments Passed as a single flat list of scalars (@_) Return is evaluated in the context it is called. @c=myadd($a,$b);sub mysort { my $a=shift; my $b=shift; … return @c;}$d=mysort(@c);

19

Perl: References

@alist=("pitt", "hanks", "cage", "cruise");%treat=("headache"=>"aspirin", "cold"=>"chicken soup");sub c2f { 9/5*$ARG[0]+32 };

$stars=\@alist; $therapy=\%treat; $coldtherapy=\$treat{"cold"};$convert=\&c2f;$pi=\3.1459;

print $$coldtherapy; #prints chicken souppush @blist, $stars->[3]; #cruise is blisted

$family={dad=>"Homer", mom=>"Marge", son=>"Bart"}

22

Defining Perl Objects:

package NBC::Horse; #namespaceour @ISA=("Animal"); #inheritancesub new{ my ($class, $name)=@_; my $self={name=>"$name", #anonymous reference sound=>"neigh"}; bless $self, $class; #blessed into an object} #return implied…sub sound { my $self=shift; return $self->{sound};}

23

Instantiation of Perl Objects:

use NBC::Horse;

my $horse=NBC::Horse->new("Mr. Ed");

#is equivalent to

my $horse=NBC::Horse::new("Horse", "Mr. Ed");

print $horse->name, " says ", $horse->sound, ".\n";

#prints Mr. Ed says neigh.

24

Perl Ties

DBMuse DB_File;tie %treat, "DB_File", "treatments";

my $rx=$treat{"Diabetes"}; $treat{"PUD"}="PrevPak";

Rolling your own:User Code Executed Codetie $s, "SomeClass" SomeClass->TIESCALAR()$p = $s $p = $obj->FETCH()$s = 10 $obj->STORE(10)

25

Perl Modules

The unit of software reuse in Perl is the module, a file that has a collection of related functions designed to be used by other programs and library modules. Every module has a public interface, a set of variables and functions that outsiders are encouraged to use. From inside the module, the interface is defined by initializing certain package variables that the standard Exporter module looks at. From outside the module, the interface is accessed by importing symbols as a side effect of the use statement. … When we talk about modules in this chapter, and traditional modules in general, we mean those that use the Exporter.

26

Perl Modules

#!/usr/bin/perl –wTpackage Cards::Poker; use Exporter;use strict;use vars qw(@ISA @EXPORTS $VERSION);@ISA=qw(Exporter);@EXPORTS=(shuffle @deck);@deck=();$VERSION=0.01;1;sub new{…sub shuffle{…

27

Perl POD

The Semantic Interface pod2man, pod2text, pod2html, pod2latex…

…=head1 NAMEMyModule…=head1 SYNOPSIS use MyModule;…=item foo($bar)Foo transforms $bars and returns a $baz=cutsub foo { my $bar=shift;…

28

Modules for Distribution

CPANh2xsTest HarnessPOD

http://www.cpan.org/misc/cpan-faq.htmlman perlmodlib

29

CPAN

30

Installing Modules

Finding Modulesfind `perl –e ‘print “@INC” ’`-name “*.pm” -printpmdesc

http://search.cpan.org/

Unixtar –xzvf; perl Makefile.PL; make; make test; make installperl –MCPAN -eshell

Windows (ActiveState Perl)perl ppm.pl

31

Language Interfaces & Distributed Perl?

XSJava.pmCORBA::OrbitCOMSOAP::Lite

32

XS

XS=eXternal SubroutineSee man pages perlguts, perlxs, perlxstut,perlcall, perlapi, h2xs, Chap. 21 of the Camel.

33

Building XS

h2xs -A -n Mytest

MANIFEST, Makefile.PL,Mytest.pm, Mytest.xs, Changes

edit Mytest.xs

perl Makefile.PL

make

make test

34

Example: XS

#include "EXTERN.h" #include "perl.h" #include "XSUB.h" MODULE = Mytest PACKAGE = Mytest void round(arg) double arg CODE: if (arg > 0.0) { arg = floor(arg + 0.5); }

else if (arg < 0.0){ arg = ceil(arg - 0.5); } else { arg = 0.0; } OUTPUT: arg

35

Example:calling XS

package Mytest;

require Dynaloader;

our @ISA=(…Dynaloader…);

bootstrap Mytest $VERSION;

36

Example: Java.pm

use Java;

$java = new Java;

$frame = $java->create_object( "java.awt.Frame","Frame's Title");

$frame->setSize(400,400);

$frame->show();

$java->do_event( $frame,"addWindowListener",\&event_handler);

37

Example: CORBA::ORBit

use CORBA::ORBit idl=>[‘echo.idl’];

my $orb=CORBA::ORB_init(“orbit-local-orb”);

open IOR, “echo.ior”;

my $ior=<IOR>;

close IOR;

my $echo=$orb->string_to_object($ior);

$echo->echoString($mystring);

38

Example: COM

http://www.extropia.com/tutorials.misc/perl_com.html

package WebMail;

use Mail::Sender;

1;

sub send {

my($from, $replyto, $to, $cc, $bcc, $smtp, $subject, $message, $file) = @_;

39

Example: Perl COM cont…

PerlCtrl.pl –t

=POD =BEGIN PerlCtrl %TypeLib = ( PackageName => 'WebMail',

TypeLibGUID => '{B3C98206-C910-11D3-B450-00805F9BDE4A}', ControlGUID => '{B3C98207-C910-11D3-B450-00805F9BDE4A}',

DispInterfaceIID=>'{B3C98208-C910-11D3-B450-00805F9BDE4A}', ControlName => 'WebMail',

… Methods => { 'send' =>

{ RetType => VT_BOOL,TotalParams => 9,

40

SOAP

Simple Object Access ProtocolXML standard

<s:Envelope xmlns:s=… >

<s:Header>…</s:Header>

<s:Body>

<n:foo xmlns:n="urn:fooserv">

<symbol xsi:type="xsd:string">bar</symbol>

</n:foo>

</s:Body>

</s:Envelope>

41

SOAP::Lite Client Example

#!/usr/bin/perl -w

use SOAP::Lite;

print SOAP::Lite

->uri('http://www.soaplite.com/Demo')

->proxy('http://services.soaplite.com/hibye.cgi')

->hi()

->result;

42

SOAP::Lite Client Example2

#!/usr/bin/perl -w

use SOAP::Lite +autodispatch=>

uri=>('http://www.soaplite.com/Temper'),

proxy=>('http://services.soaplite.com/temper.cgi');

print f2c(98.6);

43

SOAP::Lite CGI Server

#!/usr/bin/perl -w

use SOAP::Transport::HTTP;

SOAP::Transport::HTTP::CGI

->dispatch_to('Temperatures')

->handle;

package Temperatures;

sub f2c{

my ($class,$f)=$_;

return 5/9*($f-32);

}

44

SOAP HTTP Daemon Server

#!/usr/bin/perl -w

use SOAP::Transport;

use Temperatures;

my $daemon=SOAP::Transport::HTTP::Daemon

->new(LocalPort=>81)

->dispatch_to('/home/soaplite/modules');

print "started SOAP daemon at ",$daemon->url, "\n";

$daemon->handle;

45

SOAP::Lite

Object methods, and exceptions.mod_perl, mod_soap serversStated support for: .NET / COM MS SOAP/ Apache SOAP interoperability HTTPS / Jabber / MQSeries / SMTP / POP3 WSDL schema

46

SOAP::Lite suds

Autodispatch doesn't always work.Talking to .Net servers requires explicitly naming and typing variables in SOAP::Lite.

47

Components

What's a component? Legally Practically

48

A component defined "Legally"

"A component model defines specific interaction and composition standards. A component model implementation is the dedicated set of executable software elements required to support the execution of components that conform to the model"

"A software component is a software element that conforms to a component model, and can be independently deployed and composed without modification according to a composition standard"

Page 7 CBSE

49

Interaction Standard

"the mandatory requirements employed and enforced to enable software elements to directly interact with other software elements"

Distributed Computing?Interfacing other languages?

50

Interaction Standard

At a bare minimum: package, useFor completeness, use Exporter.

The unit of software reuse in Perl is the module, a file that has a collection of related functions designed to be used by other programs and library modules. Every module has a public interface, a set of variables and functions that outsiders are encouraged to use. From inside the module, the interface is defined by initializing certain package variables that the standard Exporter module looks at. From outside the module, the interface is accessed by importing symbols as a side effect of the use statement. … When we talk about modules in this chapter, and traditional modules in general, we mean those that use the Exporter.

51

A component explained "Technically"

Channel

Stub Skel

Component

Client Server

InterfaceInterface

Symbol table

Module

Perl

52

Perl Interaction Standard

A Symbol tableHow does the compiler know parameter types All parameters are passed as a list of scalars.

How do I know how many parameters, ordering, expected return, etc. Smantics. Read the module documentation. Same problem in every other component

interface.

53

Semantics

String foo (String bar, int baz)

raises fooException;

float divide (float numerator, float denominator);

54

Composition Standard

Combining of two or more software components yielding a new component behavior at a different level of abstraction.Clearly separate from OS and other componentsTypically involves: Installation Configuring Instantiating

55

Practical Components

Software Reuse"you need components for complex, mission critical systems, because they are robust, scalable, flexible"

56

Practical Components

Table 3.1 Interfaces Naming Meta data Interoperability Customization Composition Evolution Support Packaging and Deployment

57

Choosing a component model

State managementScalabilityRobustnessSecurityFault toleranceDeploymentPlatform SupportEase of Development

58

Perl as a Component Model

Conclusion From the definitions in the book, Perl fulfills

the requirements of a component model. From a practical perspective, Perl modules

are used as components. Perl (+/- SOAP::Lite) fares well in criteria

used to evaluate other component models. Our project benefits from legacy support by

using Perl.

59

Whiteboard Architecture

Portal

Formatting

Data Objects

DB Driver

Database

60

Whiteboard Architecture

portal

Web_BrowserSOAP_HTTP_Daemon

Patient

Provider

Mailbox

Note

Netscape

Palm

Session

RoleC

WB

LDAP_DriverDAM_Driver

DB2 MySQL

MySQL_Driver

SLAPd

Portal_CGI_API

CGI_Session_API

palm_API

netscape_API

Patient_API

Provider_API

Mailbox_API

Note_API

SQL

Role_API

MySQL_APIDAM_API LDAP_API

LDAPsocket

WB_API

61

Whiteboard Architecture

portal

Web_Browser

MySQL_Driver

SOAP_LiteSOAP_HTTP_Daemon

MySQL

WB

Patient

Provider

Mailbox

Note

Netscape

Palm

Session

RoleC

Portal_CGI_API

CGI_Session_API

Palm_Formatting_API

Netscape_Formatting_API

WB_API_thru_SOAP

SOAP

Patient_API

Provider_API

Mailbox_API

Note_API

MySQL_API

SQL

Role_API

WB_API

LDAP_DriverDAM_Driver

DB2 SLAPd

DAM_APILDAP_API

socket LDAP

top related