Components in Perl and SOAP Lite Team Messengers

  • Slides: 59
Download presentation
Components in Perl and SOAP: : Lite Team "Messengers" Larry Mc. Knight, MD Davis

Components in Perl and SOAP: : Lite Team "Messengers" Larry Mc. Knight, MD Davis Bu, MD Pete Stetson, MD Maryam Kamvar 1

Table of Contents: Project Overview Project Demo Perl, SOAP: : Lite and Components 2

Table of Contents: Project Overview Project Demo Perl, SOAP: : Lite and Components 2

Context: Palm. CIS Project and Application. Project goal is to reduce medical errors. n

Context: Palm. CIS Project and Application. Project goal is to reduce medical errors. n n n Improving communication (whiteboard) Timely access to patient information. Palm. CIS (the app) a wireless handheld version of the CIS. Timely access to domain knowledge (Infobuttons). 3

Communication Example: Nurse wants orders renewed. n n n Nurse identifies the Intern for

Communication Example: Nurse wants orders renewed. n n n 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. 4

Project: A Virtual Whiteboard Problem: Team structure changes rapidly. Identifying and contacting providers is

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). 5

Legacy: Web. CIS n n n Web based Clinical Information System CGI based (written

Legacy: Web. CIS n n n 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 6

Web. CIS 7

Web. CIS 7

New Problem We would like to take advantage of principles in this class –

New Problem We would like to take advantage of principles in this class – XP, Components, etc. We want to use Perl. n n 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. 8

Is Perl a Component Model? Intro to Perl Objects and Modules SOAP: : Lite

Is Perl a Component Model? Intro to Perl Objects and Modules SOAP: : Lite Component Model definitions and satisfaction with Perl Hold questions until end 9

Intro to Perl In the beginning: UNIX, C, sed, awk. 1986 – Larry Wall

Intro to Perl In the beginning: UNIX, C, sed, awk. 1986 – Larry Wall n n n Practical Extraction and Report Language Pathologically Eclectic Rubbish Lister "So lazy he created a new computer language“ w w w V 1, 12/87 Released to Usenet V 4, 3/91 The Camel book. V 5, 10/94 “Everything else” - Objects, Modules. V 5. 6, 3/2000 V 5. 8, 7/2002 Today: widespread use, cgi scripts, CPAN. 10

Why Perl? Faster development time. n n n ~1/3 – 2/3 as much code.

Why Perl? Faster development time. n n n ~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. 11

Common Myths about Perl Myth: Easy to learn; Fact: Easy to use. n n

Common Myths about Perl Myth: Easy to learn; Fact: Easy to use. n n Goal has always been power over learning. Lots of quirks, Easier ways. Myth: Slow; Fact: Mostly Fast. n n C bindings, Profiling. Use of appropriate data structures. Mod_perl. Don't use it to develop a CAD app or Micro-kernel. 12

Perl Myths continued… Myth: Insecure; Fact: Mostly Secure n n Taints, warnings, use safe

Perl Myths continued… Myth: Insecure; Fact: Mostly Secure n n Taints, warnings, use safe Security by design, not obscurity Myth: Not scalable; Fact: Very scalable n n n The defining problem. The best inter-platform, inter-language support I know of. It also scales down. Myth: Un-maintainable; Fact: It Depends n n “A very high-level language” Perl lets you get away with stuff. 13

Why ! Perl? Your boss/customer wants it done in some other language. Your problem

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. 14

Perl: Data Types n Scalars my my $null_val=""; $count++; $name="Larry"; $string=$name. $count; #string is

Perl: Data Types n Scalars my my $null_val=""; $count++; $name="Larry"; $string=$name. $count; #string is “Larry 1” Arrays, Lists my @a=(); my @stooges=qw(Larry Moe Curley); Hashes my %treatment=(diabetes=>"insulin"); my $medicine=$treatment{$disease}; 15

Perl: Numbers Type automatically set to int or floats depending on context. 12345 Integer

Perl: Numbers Type automatically set to int or floats depending on context. 12345 Integer -54321 Negative integer 12345. 67 Floating point 6. 02 E 23 Scientific notation 0 xffff Hexadecimal 0377 Octal 4_294_967_296 Underline for legibility Override with int or hex functions 16

Perl: Type conversion Hashes can be arrays %fruit=('apples', 3, 'oranges', 6); print $fruit{apples}; #prints

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, …) 17

Perl: Subroutines Arguments n n Passed as a single flat list of scalars (@_)

Perl: Subroutines Arguments n n 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); 18

Perl: References @alist=("pitt", "hanks", "cage", "cruise"); %treat=("headache"=>"aspirin", "cold"=>"chicken soup"); sub c 2 f {

Perl: References @alist=("pitt", "hanks", "cage", "cruise"); %treat=("headache"=>"aspirin", "cold"=>"chicken soup"); sub c 2 f { 9/5*$ARG[0]+32 }; $stars=@alist; $therapy=%treat; $coldtherapy=$treat{"cold"}; $convert=&c 2 f; $pi=3. 1459; print $$coldtherapy; #prints chicken soup push @blist, $stars->[3]; #cruise is blisted $family={dad=>"Homer", mom=>"Marge", son=>"Bart"} 19

Defining Perl Objects: package NBC: : Horse; #namespace our @ISA=("Animal"); #inheritance sub new{ my

Defining Perl Objects: package NBC: : Horse; #namespace our @ISA=("Animal"); #inheritance sub 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}; } 22

Instantiation of Perl Objects: use NBC: : Horse; my $horse=NBC: : Horse->new("Mr. Ed"); #is

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. 23

Perl Ties DBM use DB_File; tie %treat, "DB_File", "treatments"; my $rx=$treat{"Diabetes"}; $treat{"PUD"}="Prev. Pak"; Rolling

Perl Ties DBM use DB_File; tie %treat, "DB_File", "treatments"; my $rx=$treat{"Diabetes"}; $treat{"PUD"}="Prev. Pak"; Rolling your own: User Code tie $s, "Some. Class" $p = $s $s = 10 Executed Code Some. Class->TIESCALAR() $p = $obj->FETCH() $obj->STORE(10) 24

Perl Modules The unit of software reuse in Perl is the module, a file

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. 25

Perl Modules #!/usr/bin/perl –w. T package Cards: : Poker; use Exporter; use strict; use

Perl Modules #!/usr/bin/perl –w. T package 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{ … 26

Perl POD The Semantic Interface n pod 2 man, pod 2 text, pod 2

Perl POD The Semantic Interface n pod 2 man, pod 2 text, pod 2 html, pod 2 latex… … =head 1 NAME My. Module … =head 1 SYNOPSIS use My. Module; … =item foo($bar) Foo transforms $bars and returns a $baz =cut sub foo { my $bar=shift; … 27

Modules for Distribution CPAN h 2 xs Test Harness POD http: //www. cpan. org/misc/cpan-faq.

Modules for Distribution CPAN h 2 xs Test Harness POD http: //www. cpan. org/misc/cpan-faq. html man perlmodlib 28

CPAN 29

CPAN 29

Installing Modules Finding Modules find `perl –e ‘print “@INC” ’`-name “*. pm” -print pmdesc

Installing Modules Finding Modules find `perl –e ‘print “@INC” ’`-name “*. pm” -print pmdesc http: //search. cpan. org/ Unix tar –xzvf; perl Makefile. PL; make test; make install perl –MCPAN -eshell Windows (Active. State Perl) perl ppm. pl 30

Language Interfaces & Distributed Perl? XS Java. pm CORBA: : Orbit COM SOAP: :

Language Interfaces & Distributed Perl? XS Java. pm CORBA: : Orbit COM SOAP: : Lite 31

XS XS=e. Xternal Subroutine See man pages perlguts, perlxstut, perlcall, perlapi, h 2 xs,

XS XS=e. Xternal Subroutine See man pages perlguts, perlxstut, perlcall, perlapi, h 2 xs, Chap. 21 of the Camel. 32

Building XS h 2 xs -A -n Mytest MANIFEST, Makefile. PL, Mytest. pm, Mytest.

Building XS h 2 xs -A -n Mytest MANIFEST, Makefile. PL, Mytest. pm, Mytest. xs, Changes edit Mytest. xs perl Makefile. PL make test 33

Example: XS #include "EXTERN. h" #include "perl. h" #include "XSUB. h" MODULE = Mytest

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 34

Example: calling XS package Mytest; … require Dynaloader; … our @ISA=(…Dynaloader…); … bootstrap Mytest

Example: calling XS package Mytest; … require Dynaloader; … our @ISA=(…Dynaloader…); … bootstrap Mytest $VERSION; 35

Example: Java. pm use Java; $java = new Java; $frame = $java->create_object( "java. awt.

Example: Java. pm use Java; $java = new Java; $frame = $java->create_object( "java. awt. Frame", "Frame's Title"); $frame->set. Size(400, 400); $frame->show(); $java->do_event( $frame, "add. Window. Listener", &event_handler); … 36

Example: CORBA: : ORBit use CORBA: : ORBit idl=>[‘echo. idl’]; my $orb=CORBA: : ORB_init(“orbit-local-orb”);

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->echo. String($mystring); 37

Example: COM http: //www. extropia. com/tutorials. misc/perl_com. html package Web. Mail; use Mail: :

Example: COM http: //www. extropia. com/tutorials. misc/perl_com. html package Web. Mail; use Mail: : Sender; 1; sub send { my($from, $replyto, $cc, $bcc, $smtp, $subject, $message, $file) = @_; … 38

Example: Perl COM cont… Perl. Ctrl. pl –t =POD =BEGIN Perl. Ctrl %Type. Lib

Example: Perl COM cont… Perl. Ctrl. pl –t =POD =BEGIN Perl. Ctrl %Type. Lib = ( Package. Name => 'Web. Mail', Type. Lib. GUID => '{B 3 C 98206 -C 910 -11 D 3 -B 450 -00805 F 9 BDE 4 A}', Control. GUID => '{B 3 C 98207 -C 910 -11 D 3 -B 450 -00805 F 9 BDE 4 A}', Disp. Interface. IID=>'{B 3 C 98208 -C 910 -11 D 3 -B 45000805 F 9 BDE 4 A}', Control. Name => 'Web. Mail', … Methods => { 'send' => { Ret. Type => VT_BOOL, Total. Params => 9, 39

SOAP Simple Object Access Protocol XML standard <s: Envelope xmlns: s=… > <s: Header>…</s:

SOAP Simple Object Access Protocol XML 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> 40

SOAP: : Lite Client Example #!/usr/bin/perl -w use SOAP: : Lite; print SOAP: :

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; 41

SOAP: : Lite Client Example 2 #!/usr/bin/perl -w use SOAP: : Lite +autodispatch=> uri=>('http:

SOAP: : Lite Client Example 2 #!/usr/bin/perl -w use SOAP: : Lite +autodispatch=> uri=>('http: //www. soaplite. com/Temper'), proxy=>('http: //services. soaplite. com/temper. cgi'); print f 2 c(98. 6); 42

SOAP: : Lite CGI Server #!/usr/bin/perl -w use SOAP: : Transport: : HTTP; SOAP:

SOAP: : Lite CGI Server #!/usr/bin/perl -w use SOAP: : Transport: : HTTP; SOAP: : Transport: : HTTP: : CGI ->dispatch_to('Temperatures') ->handle; package Temperatures; sub f 2 c{ my ($class, $f)=$_; return 5/9*($f-32); } 43

SOAP HTTP Daemon Server #!/usr/bin/perl -w use SOAP: : Transport; use Temperatures; my $daemon=SOAP:

SOAP HTTP Daemon Server #!/usr/bin/perl -w use SOAP: : Transport; use Temperatures; my $daemon=SOAP: : Transport: : HTTP: : Daemon ->new(Local. Port=>81) ->dispatch_to('/home/soaplite/modules'); print "started SOAP daemon at ", $daemon->url, "n"; $daemon->handle; 44

SOAP: : Lite Object methods, and exceptions. mod_perl, mod_soap servers Stated support for: n

SOAP: : Lite Object methods, and exceptions. mod_perl, mod_soap servers Stated support for: n n . NET / COM MS SOAP/ Apache SOAP interoperability HTTPS / Jabber / MQSeries / SMTP / POP 3 WSDL schema 45

SOAP: : Lite suds Autodispatch doesn't always work. Talking to. Net servers requires explicitly

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

Components What's a component? n n Legally Practically 47

Components What's a component? n n Legally Practically 47

A component defined "Legally" "A component model defines specific interaction and composition standards. A

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 48

Interaction Standard "the mandatory requirements employed and enforced to enable software elements to directly

Interaction Standard "the mandatory requirements employed and enforced to enable software elements to directly interact with other software elements" Distributed Computing? Interfacing other languages? 49

Interaction Standard At a bare minimum: package, use For completeness, use Exporter. The unit

Interaction Standard At a bare minimum: package, use For 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. 50

A component explained "Technically" Client Server Module Interface Stub Symbol table Component Skel Interface

A component explained "Technically" Client Server Module Interface Stub Symbol table Component Skel Interface Channel Perl 51

Perl Interaction Standard A Symbol table How does the compiler know parameter types n

Perl Interaction Standard A Symbol table How does the compiler know parameter types n All parameters are passed as a list of scalars. How do I know how many parameters, ordering, expected return, etc. n n n Smantics. Read the module documentation. Same problem in every other component interface. 52

Semantics String foo (String bar, int baz) raises foo. Exception; float divide (float numerator,

Semantics String foo (String bar, int baz) raises foo. Exception; float divide (float numerator, float denominator); 53

Composition Standard Combining of two or more software components yielding a new component behavior

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 components Typically involves: n n n Installation Configuring Instantiating 54

Practical Components Software Reuse "you need components for complex, mission critical systems, because they

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

Practical Components Table 3. 1 n n n n Interfaces Naming Meta data Interoperability

Practical Components Table 3. 1 n n n n Interfaces Naming Meta data Interoperability Customization Composition Evolution Support Packaging and Deployment 56

Choosing a component model State management Scalability Robustness Security Fault tolerance Deployment Platform Support

Choosing a component model State management Scalability Robustness Security Fault tolerance Deployment Platform Support Ease of Development 57

Perl as a Component Model Conclusion n n From the definitions in the book,

Perl as a Component Model Conclusion n n 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. 58

Whiteboard Architecture Portal Formatting Data Objects DB Driver Database 59

Whiteboard Architecture Portal Formatting Data Objects DB Driver Database 59

Whiteboard Architecture 60

Whiteboard Architecture 60

Whiteboard Architecture 61

Whiteboard Architecture 61