1 / 59

Components in Perl and SOAP::Lite

Components in Perl and SOAP::Lite. Team "Messengers" Larry McKnight, MD Davis Bu, MD Pete Stetson, MD Maryam Kamvar. Table of Contents:. Project Overview Project Demo Perl, SOAP::Lite and Components. Context: PalmCIS. Project and Application. Project goal is to reduce medical errors.

odeda
Télécharger la présentation

Components in Perl and SOAP::Lite

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Components in Perland SOAP::Lite Team "Messengers" Larry McKnight, MD Davis Bu, MD Pete Stetson, MD Maryam Kamvar

  2. Table of Contents: • Project Overview • Project Demo • Perl, 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 Perl • Perl Objects and Modules • SOAP::Lite • Component 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 • Scalars my $null_val=""; my $count++; my $name="Larry"; my $string=$name.$count; #string is “Larry1” Arrays, Lists my @a=(); my @stooges=qw(Larry Moe Curley); Hashes my %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.67Floating point 6.02E23Scientific notation 0xffffHexadecimal 0377Octal 4_294_967_296Underline 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 soup push @blist, $stars->[3]; #cruise is blisted $family={dad=>"Homer", mom=>"Marge", son=>"Bart"}

  20. 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}; }

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

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

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

  24. Perl Modules #!/usr/bin/perl –wT 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{ …

  25. Perl POD The Semantic Interface • pod2man, pod2text, pod2html, pod2latex… … =head1 NAME MyModule … =head1 SYNOPSIS use MyModule; … =item foo($bar) Foo transforms $bars and returns a $baz =cut sub foo { my $bar=shift; …

  26. Modules for Distribution • CPAN • h2xs • Test Harness • POD http://www.cpan.org/misc/cpan-faq.html man perlmodlib

  27. CPAN

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

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

  30. XS • XS=eXternal Subroutine • See man pages perlguts, perlxs, perlxstut,perlcall, perlapi, h2xs, Chap. 21 of the Camel.

  31. Building XS h2xs -A -n Mytest MANIFEST, Makefile.PL,Mytest.pm, Mytest.xs, Changes edit Mytest.xs perl Makefile.PL make make test

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

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

  34. 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); …

  35. 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);

  36. 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) = @_; …

  37. 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,

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

  39. 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;

  40. 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);

  41. 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); }

  42. 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;

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

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

  45. Components • What's a component? • Legally • Practically

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

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

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

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

  50. Perl Interaction Standard • A Symbol table • How 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.

More Related