next prev What Works Slide #97

Facade

Hides the underlying complexity.

Example: LWP vs LWP::Simple

         use LWP::UserAgent;
         $ua = LWP::UserAgent->new;
         $ua->agent("$0/0.1 " . $ua->agent);
         # $ua->agent("Mozilla/8.0") # pretend we are very capable browser
         $req = HTTP::Request->new(GET => 'http://www.linpro.no/lwp');
         $req->header('Accept' => 'text/html');
         # send request
         $res = $ua->request($req);
         # check the outcome
         if ($res->is_success) {
            print $res->content;
         }
         use LWP::Simple;
         getprint('http://www.linpro.no/lwp');

Sometimes, you just don't need all that power.


next prev ToC Copyright © 2002-2003 Norman Nunley & Michael G Schwern