Changeset 8203afd for perlwrap.pm
- Timestamp:
- Jan 9, 2007, 11:33:44 PM (18 years ago)
- Branches:
- master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- d609dd6
- Parents:
- ffe70f9
- git-author:
- Nelson Elhage <nelhage@mit.edu> (01/09/07 18:50:40)
- git-committer:
- Nelson Elhage <nelhage@mit.edu> (01/09/07 23:33:44)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
perlwrap.pm
r3354cea5 r8203afd 9 9 use warnings; 10 10 11 package owl;11 package BarnOwl; 12 12 13 13 14 14 BEGIN { 15 15 # bootstrap in C bindings and glue 16 bootstrap owl 1.2; 16 *owl:: = \*BarnOwl::; 17 bootstrap BarnOwl 1.2; 17 18 }; 18 19 … … 28 29 my ($m) = @_; 29 30 $m->legacy_populate_global(); 30 return & owl::format_msg($m);31 return &BarnOwl::format_msg($m); 31 32 } 32 33 … … 35 36 my ($m) = @_; 36 37 $m->legacy_populate_global(); 37 return & owl::receive_msg($m);38 } 39 40 # make owl::<command>("foo") be aliases to owl::command("<command> foo");38 return &BarnOwl::Hooks::receive_msg($m); 39 } 40 41 # make BarnOwl::<command>("foo") be aliases to BarnOwl::command("<command> foo"); 41 42 sub AUTOLOAD { 42 43 our $AUTOLOAD; … … 44 45 $called =~ s/.*:://; 45 46 $called =~ s/_/-/g; 46 return & owl::command("$called ".join(" ",@_));47 return &BarnOwl::command("$called ".join(" ",@_)); 47 48 } 48 49 … … 70 71 71 72 no warnings 'uninitialized'; 72 owl::new_command_internal($name, $func, $args{summary}, $args{usage}, $args{description});73 } 74 75 ##################################################################### 76 ##################################################################### 77 78 package owl::Message;73 BarnOwl::new_command_internal($name, $func, $args{summary}, $args{usage}, $args{description}); 74 } 75 76 ##################################################################### 77 ##################################################################### 78 79 package BarnOwl::Message; 79 80 80 81 sub new { … … 82 83 my %args = (@_); 83 84 if($class eq __PACKAGE__ && $args{type}) { 84 $class = " owl::Message::" . ucfirst $args{type};85 $class = "BarnOwl::Message::" . ucfirst $args{type}; 85 86 } 86 87 return bless {%args}, $class; … … 137 138 sub delete { 138 139 my ($m) = @_; 139 & owl::command("delete --id ".$m->id);140 &BarnOwl::command("delete --id ".$m->id); 140 141 } 141 142 142 143 sub undelete { 143 144 my ($m) = @_; 144 & owl::command("undelete --id ".$m->id);145 &BarnOwl::command("undelete --id ".$m->id); 145 146 } 146 147 … … 169 170 sub legacy_populate_global { 170 171 my ($m) = @_; 171 $ owl::direction = $m->direction ;172 $ owl::type = $m->type ;173 $ owl::id = $m->id ;174 $ owl::class = $m->class ;175 $ owl::instance = $m->instance ;176 $ owl::recipient = $m->recipient ;177 $ owl::sender = $m->sender ;178 $ owl::realm = $m->realm ;179 $ owl::opcode = $m->opcode ;180 $ owl::zsig = $m->zsig ;181 $ owl::msg = $m->body ;182 $ owl::time = $m->time ;183 $ owl::host = $m->host ;184 $ owl::login = $m->login ;185 $ owl::auth = $m->auth ;172 $BarnOwl::direction = $m->direction ; 173 $BarnOwl::type = $m->type ; 174 $BarnOwl::id = $m->id ; 175 $BarnOwl::class = $m->class ; 176 $BarnOwl::instance = $m->instance ; 177 $BarnOwl::recipient = $m->recipient ; 178 $BarnOwl::sender = $m->sender ; 179 $BarnOwl::realm = $m->realm ; 180 $BarnOwl::opcode = $m->opcode ; 181 $BarnOwl::zsig = $m->zsig ; 182 $BarnOwl::msg = $m->body ; 183 $BarnOwl::time = $m->time ; 184 $BarnOwl::host = $m->host ; 185 $BarnOwl::login = $m->login ; 186 $BarnOwl::auth = $m->auth ; 186 187 if ($m->fields) { 187 @ owl::fields = @{$m->fields};188 @BarnOwl::fields = @{$m->fields}; 188 189 @main::fields = @{$m->fields}; 189 190 } else { 190 @ owl::fields = undef;191 @BarnOwl::fields = undef; 191 192 @main::fields = undef; 192 193 } … … 200 201 ##################################################################### 201 202 202 package owl::Message::Admin;203 204 use base qw( owl::Message );203 package BarnOwl::Message::Admin; 204 205 use base qw( BarnOwl::Message ); 205 206 206 207 sub header { return shift->{"header"}; } … … 209 210 ##################################################################### 210 211 211 package owl::Message::Generic;212 213 use base qw( owl::Message );214 215 ##################################################################### 216 ##################################################################### 217 218 package owl::Message::AIM;219 220 use base qw( owl::Message );212 package BarnOwl::Message::Generic; 213 214 use base qw( BarnOwl::Message ); 215 216 ##################################################################### 217 ##################################################################### 218 219 package BarnOwl::Message::AIM; 220 221 use base qw( BarnOwl::Message ); 221 222 222 223 # all non-loginout AIM messages are personal for now... … … 228 229 ##################################################################### 229 230 230 package owl::Message::Zephyr;231 232 use base qw( owl::Message );231 package BarnOwl::Message::Zephyr; 232 233 use base qw( BarnOwl::Message ); 233 234 234 235 sub login_tty { … … 263 264 my ($m) = @_; 264 265 my $sender = $m->sender; 265 my $realm = owl::zephyr_getrealm();266 my $realm = BarnOwl::zephyr_getrealm(); 266 267 $sender =~ s/\@$realm$//; 267 268 return $sender; … … 285 286 package owl; 286 287 288 ################################################################################ 289 # Mainloop hook 290 ################################################################################ 291 292 our $shutdown; 293 $shutdown = 0; 294 our $reload; 295 $reload = 0; 296 297 #Run this on start and reload. Adds modules 298 sub onStart 299 { 300 reload_init(); 301 loadModules(); 302 } 303 ################################################################################ 304 # Reload Code, taken from /afs/sipb/user/jdaniel/project/owl/perl 305 ################################################################################ 306 sub reload_hook (@) 307 { 308 BarnOwl::Hooks::startup(); 309 return 1; 310 } 311 312 sub reload 313 { 314 # Use $reload to tell modules that we're performing a reload. 315 { 316 local $reload = 1; 317 BarnOwl::mainloop_hook(); 318 } 319 320 @BarnOwl::Hooks::onMainLoop = (); 321 @BarnOwl::Hooks::onStartSubs = (); 322 323 # Do reload 324 package main; 325 if (do "$ENV{HOME}/.owlconf" && BarnOwl::reload_hook(@_)) 326 { 327 return "owlconf reloaded"; 328 } 329 else 330 { 331 return "$ENV{HOME}/.owlconf load attempted, but error encountered:\n$@"; 332 } 333 package owl; 334 } 335 336 sub reload_init () 337 { 338 BarnOwl::command('alias reload perl BarnOwl::reload()'); 339 BarnOwl::command('bindkey global "C-x C-r" command reload'); 340 } 341 342 ################################################################################ 343 # Loads modules from ~/.owl/modules and owl's data directory 344 ################################################################################ 345 346 sub loadModules () { 347 my @modules; 348 my $rv; 349 foreach my $dir ( BarnOwl::get_data_dir() . "/modules", 350 $ENV{HOME} . "/.owl/modules" ) 351 { 352 opendir( MODULES, $dir ); 353 354 # source ./modules/*.pl 355 @modules = grep( /\.pl$/, readdir(MODULES) ); 356 357 foreach my $mod (@modules) { 358 owl::error("Loading $dir/$mod..."); 359 unless ($rv = do "$dir/$mod") { 360 BarnOwl::error("Couldn't load $dir/$mod:\n $@") if $@; 361 BarnOwl::error("Couldn't run $dir/$mod:\n $!") unless defined $rv; 362 } 363 } 364 closedir(MODULES); 365 } 366 } 367 368 package BarnOwl::Hooks; 369 287 370 # Arrays of subrefs to be called at specific times. 288 371 our @onStartSubs = (); … … 291 374 our @onGetBuddyList = (); 292 375 293 ################################################################################294 # Mainloop hook295 ################################################################################296 297 our $shutdown;298 $shutdown = 0;299 our $reload;300 $reload = 0;301 302 376 # Functions to call hook lists 303 377 sub runHook($@) … … 315 389 } 316 390 317 sub mainloop_hook318 {319 runHook(\@onMainLoop);320 }321 322 391 ################################################################################ 323 392 # Startup and Shutdown code … … 325 394 sub startup 326 395 { 327 # Modern versions of owl provides a great place to have startup stuff. 328 # Put things in ~/.owl/startup 329 onStart(); 330 } 331 332 sub shutdown 333 { 334 # Modern versions of owl provides a great place to have shutdown stuff. 335 # Put things in ~/.owl/shutdown 336 337 # use $shutdown to tell modules that that's what we're doing. 338 $shutdown = 1; 339 mainloop_hook(); 340 } 341 342 #Run this on start and reload. Adds modules and runs their startup functions. 343 sub onStart 344 { 345 reload_init(); 396 # Modern versions of owl provides a great place to have startup stuff. 397 # Put things in ~/.owl/startup 398 346 399 #So that the user's .owlconf can have startsubs, we don't clear 347 400 #onStartSubs; reload does however … … 350 403 @onGetBuddyList = (); 351 404 352 loadModules(); 405 BarnOwl::onStart(); 406 353 407 runHook(\@onStartSubs); 354 } 355 ################################################################################ 356 # Reload Code, taken from /afs/sipb/user/jdaniel/project/owl/perl 357 ################################################################################ 358 sub reload_hook (@) 359 { 360 onStart(); 361 return 1; 362 } 363 364 sub reload 365 { 366 # Use $reload to tell modules that we're performing a reload. 367 $reload = 1; 368 owl::mainloop_hook(); 369 $reload = 0; 370 @onMainLoop = (); 371 @onStartSubs = (); 372 373 # Do reload 374 package main; 375 if (do "$ENV{HOME}/.owlconf" && owl::reload_hook(@_)) 376 { 377 return "owlconf reloaded"; 378 } 379 else 380 { 381 return "$ENV{HOME}/.owlconf load attempted, but error encountered:\n$@"; 382 } 383 package owl; 384 } 385 386 sub reload_init () 387 { 388 owl::command('alias reload perl owl::reload()'); 389 owl::command('bindkey global "C-x C-r" command reload'); 390 } 391 392 ################################################################################ 393 # Loads modules from ~/.owl/modules and owl's data directory 394 ################################################################################ 395 396 sub loadModules () { 397 my @modules; 398 my $rv; 399 foreach my $dir ( owl::get_data_dir() . "/modules", 400 $ENV{HOME} . "/.owl/modules" ) 401 { 402 opendir( MODULES, $dir ); 403 404 # source ./modules/*.pl 405 @modules = grep( /\.pl$/, readdir(MODULES) ); 406 407 foreach my $mod (@modules) { 408 unless ($rv = do "$dir/$mod") { 409 owl::error("Couldn't load $dir/$mod:\n $@") if $@; 410 owl::error("Couldn't run $dir/$mod:\n $!") unless defined $rv; 411 } 412 } 413 closedir(MODULES); 414 } 415 } 416 417 408 409 BarnOwl::startup() if *BarnOwl::startup{CODE}; 410 } 411 412 sub shutdown 413 { 414 # Modern versions of owl provides a great place to have shutdown stuff. 415 # Put things in ~/.owl/shutdown 416 417 # use $shutdown to tell modules that that's what we're doing. 418 $BarnOwl::shutdown = 1; 419 BarnOwl::mainloop_hook(); 420 421 BarnOwl::shutdown() if *BarnOwl::shutdown{CODE}; 422 } 423 424 sub mainloop_hook 425 { 426 runHook(\@onMainLoop); 427 BarnOwl::mainlook_hook() if *BarnOwl::mainloop_hook{CODE}; 428 } 418 429 419 430 ################################################################################ … … 425 436 my $m = shift; 426 437 runHook(\@onReceiveMsg, $m); 438 BarnOwl::receive_msg($m) if *BarnOwl::receive_msg{CODE}; 427 439 } 428 440 … … 433 445 sub get_blist 434 446 { 435 my $m = shift; 436 return runHook_accumulate(\@onGetBuddyList, $m); 447 return runHook_accumulate(\@onGetBuddyList); 437 448 } 438 449 … … 446 457 onMainLoop 447 458 onGetBuddyList ) { 448 *{"main::".$hook} = \*{"owl::".$hook}; 459 *{"main::".$hook} = \*{"BarnOwl::Hooks::".$hook}; 460 *{"owl::".$hook} = \*{"BarnOwl::Hooks::".$hook}; 449 461 } 450 462 } 451 463 452 464 # load the config file 453 if (-r $ owl::configfile) {465 if (-r $BarnOwl::configfile) { 454 466 undef $@; 455 do $ owl::configfile;467 do $BarnOwl::configfile; 456 468 die $@ if $@; 457 469 }
Note: See TracChangeset
for help on using the changeset viewer.