ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/urxvt.pm
(Generate patch)

Comparing rxvt-unicode/src/urxvt.pm (file contents):
Revision 1.67 by root, Mon Jan 9 19:29:06 2006 UTC vs.
Revision 1.68 by root, Mon Jan 9 20:00:31 2006 UTC

445sub verbose { 445sub verbose {
446 my ($level, $msg) = @_; 446 my ($level, $msg) = @_;
447 warn "$msg\n" if $level <= $verbosity; 447 warn "$msg\n" if $level <= $verbosity;
448} 448}
449 449
450# find on_xxx subs in the package and register them
451# as hooks
452sub register_package($) {
453 my ($pkg) = @_;
454
455 for my $htype (0.. $#HOOKNAME) {
456 my $name = $HOOKNAME[$htype];
457
458 my $ref = $pkg->can ("on_" . lc $name)
459 or next;
460
461 $TERM->{_hook}[$htype]{$pkg} = $ref;
462 $hook_count[$htype]++
463 or set_should_invoke $htype, 1;
464 }
465}
466
467my $extension_pkg = "extension0000"; 450my $extension_pkg = "extension0000";
468my %extension_pkg; 451my %extension_pkg;
469 452
470# load a single script into its own package, once only 453# load a single script into its own package, once only
471sub extension_package($) { 454sub extension_package($) {
499 my $htype = shift; 482 my $htype = shift;
500 483
501 if ($htype == 0) { # INIT 484 if ($htype == 0) { # INIT
502 my @dirs = ((split /:/, $TERM->resource ("perl_lib")), "$LIBDIR/perl"); 485 my @dirs = ((split /:/, $TERM->resource ("perl_lib")), "$LIBDIR/perl");
503 486
504 my %want_ext; 487 my %ext_arg;
505 488
506 for (map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2) { 489 for (map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2) {
507 if ($_ eq "default") { 490 if ($_ eq "default") {
508 $want_ext{$_}++ for qw(selection option-popup selection-popup); 491 $ext_arg{$_} ||= [] for qw(selection option-popup selection-popup);
509 } elsif (/^-(.*)$/) { 492 } elsif (/^-(.*)$/) {
510 delete $want_ext{$1}; 493 delete $ext_arg{$1};
494 } elsif (/^([^<]+)<(.*)>$/) {
495 push @{ $ext_arg{$1} }, $2;
511 } else { 496 } else {
512 $want_ext{$_}++; 497 $ext_arg{$_} ||= [];
513 } 498 }
514 } 499 }
515 500
516 for my $ext (keys %want_ext) { 501 while (my ($ext, $argv) = each %ext_arg) {
517 my @files = grep -f $_, map "$_/$ext", @dirs; 502 my @files = grep -f $_, map "$_/$ext", @dirs;
518 503
519 if (@files) { 504 if (@files) {
520 register_package extension_package $files[0]; 505 $TERM->register_package (extension_package $files[0], $argv);
521 } else { 506 } else {
522 warn "perl extension '$ext' not found in perl library search path\n"; 507 warn "perl extension '$ext' not found in perl library search path\n";
523 } 508 }
524 } 509 }
525 510
534 if $verbosity >= 10; 519 if $verbosity >= 10;
535 520
536 keys %$cb; 521 keys %$cb;
537 522
538 while (my ($pkg, $cb) = each %$cb) { 523 while (my ($pkg, $cb) = each %$cb) {
539 eval { 524 $retval = eval { $cb->($TERM->{_pkg}{$pkg}, @_) }
540 $retval = $cb->(
541 $TERM->{_pkg}{$pkg} ||= do {
542 my $proxy = bless { }, $pkg;
543 Scalar::Util::weaken ($proxy->{term} = $TERM);
544 $proxy
545 },
546 @_,
547 ) and last; 525 and last;
548 }; 526
549 if ($@) { 527 if ($@) {
550 $TERM->ungrab; # better to lose the grab than the session 528 $TERM->ungrab; # better to lose the grab than the session
551 warn $@; 529 warn $@;
552 } 530 }
553 } 531 }
674package urxvt::term; 652package urxvt::term;
675 653
676=head2 The C<urxvt::term> Class 654=head2 The C<urxvt::term> Class
677 655
678=over 4 656=over 4
657
658=cut
659
660# find on_xxx subs in the package and register them
661# as hooks
662sub register_package {
663 my ($self, $pkg, $argv) = @_;
664
665 my $proxy = bless { argv => $argv }, $pkg;
666 Scalar::Util::weaken ($proxy->{term} = $TERM);
667
668 $self->{_pkg}{$pkg} = $proxy;
669
670 for my $htype (0.. $#HOOKNAME) {
671 my $name = $HOOKNAME[$htype];
672
673 my $ref = $pkg->can ("on_" . lc $name)
674 or next;
675
676 $self->{_hook}[$htype]{$pkg} = $ref;
677 $hook_count[$htype]++
678 or urxvt::set_should_invoke $htype, 1;
679 }
680}
679 681
680=item $term->destroy 682=item $term->destroy
681 683
682Destroy the terminal object (close the window, free resources etc.). 684Destroy the terminal object (close the window, free resources etc.).
683 685

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines