2007년 5월 9일 수요일

CGI::XMLApplication -- Object Oriented Interface for CGI Script Applications

PERL로 SOAP구현을 공부하다 나온 라이브러리

샘플
use CGI::XMLApplication;

  $script = new CGI::XMLApplication;
  $script->setStylesheetPath( "the/path/to/the/stylesheets" );

  # either this for simple scripts
  $script->run();
  # or if you need more control ...
  $script->run(%context_hash); # or a context object

설명
PERL 프로그래머에게 XML/XSLT를 function으로 만들수 있는 기능 제공한다.
 XML::LibXML/ XML::LibXSLT 의 강력한 기능을 사용할 수 있게 해준다.

코드 레벨의 프로젝트 관리가 가능하도록 해준다네? 어떻게 해준다는거지?
웹 어플리케이션을 여러개의 간단한 파트로 나눌 수 있게 해준다라..대부분의 코드들을 심플한 상태로 둘 수 있고 XMLApplication이 이들을 안정적으로 유지시켜 준다.

이 모듈을 기존의 CGI모듈을 확장해 준다. 물론 모든 기존의 CGI모듈을 여전히 사용이 가능하다. ..좋구만...CGI모듈의 확장판이었구나. 그래서 SOAP에서 사용됐던것 같음

흠 결과물의 layout을 읽기 좋게 만들어 주는 효과도 있다네.
그래서 setStylesheetPath가 있나 보네.

flow도 있군...참조 http://search.cpan.org/~phish/CGI-XMLApplication-1.1.3/XMLApplication.pm

어떻게 Event를 catch하는가?

클라이언트
    <!-- SOME HTML CODE -->
    <input type="submit" name="dummy" value="whatever" />
    <!-- SOME MORE HTML :) -->


어플리케이션
 # Application Module
package myApp;

use CGI::XMLApplication;
@ISA = qw(CGI::XMLApplication);

sub registerEvents { qw( dummy ); } # list of event names

# ...

sub event_dummy {
     my ( $self, $context ) = @_;

     # your event code goes here

     return 0;
}

cgi 스크립트들은 submit버튼을 통해 event가 발새되고 한다.
많은경우 쿼리 스트링을 통해 event를 발생시키기 쉽지 않다, 이런경우 XMLApplication은 event_init() 를 사용해 스페셜 event를 전송 할 수 있다(예를들면 application error와 같은), 이 작업은 sendEvent() function을 사용해 구현이 가능하다. 하지만 반듯이 regist된 function만을 사용할 수 있다.

method registerEvents
method run

Event System

XMLApplication은 두가지 부분으로 구성되어 있다. 1) 서버로 부터 스크립트 실행하는 부분 2) 어플리케이션 모듈이 스크립트로 부터 불려져 로드되는 부분

CGI::XMLApplication 두가지 타입의 이벤트 핸들러가 있다.  아 띠...모뇽~
implicit events
registerEvents를 사용해 이름이나 필요치 않은 이벤트 들을 정의?

Common to all applications and explicit events
차이가 뭐지?

package myApp;
  use CGI::XMLApplication;
  @ISA = qw(CGI::XMLApplication);

  sub registerEvents { qw( missing ... ) ; }

  # event_init is an implicit event
  sub event_init {
     my ( $self, $context ) = @_;
     if ( not ( defined $self->param( $paraname ) && length $self->param( $paramname ) ) ){
        # the parameter is not correctly filled
        $self->sendEvent( 'missing' );
     }
     else {

    ... some more initialization ...

     }
     return 0;
  }

  ... more code ...

  # event_missing is an explicit event.
  sub event_missing {
     my ( $self , $context ) = @_;

     ... your error handling code goes ...

     return -4 if $panic;  # just for illustration
     return 0;
  }

솔직히 &missing하는거랑 차이가 뭔지 모르겠네..쓰바..

Implicit Events

the XML Serialization











댓글 없음:

댓글 쓰기