… | |
… | |
67 | package EV; |
67 | package EV; |
68 | |
68 | |
69 | use strict; |
69 | use strict; |
70 | |
70 | |
71 | BEGIN { |
71 | BEGIN { |
72 | our $VERSION = '1.4'; |
72 | our $VERSION = '1.5'; |
73 | use XSLoader; |
73 | use XSLoader; |
74 | XSLoader::load "EV", $VERSION; |
74 | XSLoader::load "EV", $VERSION; |
75 | } |
75 | } |
76 | |
76 | |
77 | @EV::IO::ISA = |
77 | @EV::IO::ISA = |
78 | @EV::Timer::ISA = |
78 | @EV::Timer::ISA = |
79 | @EV::Periodic::ISA = |
79 | @EV::Periodic::ISA = |
80 | @EV::Signal::ISA = |
80 | @EV::Signal::ISA = |
|
|
81 | @EV::Child::ISA = |
|
|
82 | @EV::Stat::ISA = |
81 | @EV::Idle::ISA = |
83 | @EV::Idle::ISA = |
82 | @EV::Prepare::ISA = |
84 | @EV::Prepare::ISA = |
83 | @EV::Check::ISA = |
85 | @EV::Check::ISA = |
84 | @EV::Child::ISA = |
|
|
85 | @EV::Embed::ISA = |
86 | @EV::Embed::ISA = |
86 | @EV::Stat::ISA = "EV::Watcher"; |
87 | @EV::Fork::ISA = |
|
|
88 | "EV::Watcher"; |
87 | |
89 | |
88 | =head1 BASIC INTERFACE |
90 | =head1 BASIC INTERFACE |
89 | |
91 | |
90 | =over 4 |
92 | =over 4 |
91 | |
93 | |
… | |
… | |
551 | watcher for all pids). |
553 | watcher for all pids). |
552 | |
554 | |
553 | =back |
555 | =back |
554 | |
556 | |
555 | |
557 | |
|
|
558 | =head3 STAT WATCHERS - did the file attributes just change? |
|
|
559 | |
|
|
560 | =over 4 |
|
|
561 | |
|
|
562 | =item $w = EV::stat $path, $interval, $callback |
|
|
563 | |
|
|
564 | =item $w = EV::stat_ns $path, $interval, $callback |
|
|
565 | |
|
|
566 | Call the callback when a file status change has been detected on |
|
|
567 | C<$path>. The C<$path> does not need to exist, changing from "path exists" |
|
|
568 | to "path does not exist" is a status change like any other. |
|
|
569 | |
|
|
570 | The C<$interval> is a recommended polling interval for systems where |
|
|
571 | OS-supported change notifications don't exist or are not supported. If |
|
|
572 | you use C<0> then an unspecified default is used (which is highly |
|
|
573 | recommended!), which is to be expected to be around five seconds usually. |
|
|
574 | |
|
|
575 | This watcher type is not meant for massive numbers of stat watchers, |
|
|
576 | as even with OS-supported change notifications, this can be |
|
|
577 | resource-intensive. |
|
|
578 | |
|
|
579 | The C<stat_ns> variant doesn't start (activate) the newly created watcher. |
|
|
580 | |
|
|
581 | =item ... = $w->stat |
|
|
582 | |
|
|
583 | This call is very similar to the perl C<stat> built-in: It stats (using |
|
|
584 | C<lstat>) the path specified in the watcher and sets perls stat cache (as |
|
|
585 | well as EV's idea of the current stat values) to the values found. |
|
|
586 | |
|
|
587 | In scalar context, a boolean is return indicating success or failure of |
|
|
588 | the stat. In list context, the same 13-value list as with stat is returned |
|
|
589 | (except that the blksize and blocks fields are not reliable). |
|
|
590 | |
|
|
591 | In the case of an error, errno is set to C<ENOENT> (regardless of the |
|
|
592 | actual error value) and the C<nlink> value is forced to zero (if the stat |
|
|
593 | was successful then nlink is guaranteed to be non-zero). |
|
|
594 | |
|
|
595 | See also the next two entries for more info. |
|
|
596 | |
|
|
597 | =item ... = $w->attr |
|
|
598 | |
|
|
599 | Just like C<< $w->stat >>, but without the initial stat'ing: this returns |
|
|
600 | the values most recently detected by EV. See the next entry for more info. |
|
|
601 | |
|
|
602 | =item ... = $w->prev |
|
|
603 | |
|
|
604 | Just like C<< $w->stat >>, but without the initial stat'ing: this returns |
|
|
605 | the previous set of values, before the change. |
|
|
606 | |
|
|
607 | That is, when the watcher callback is invoked, C<< $w->prev >> will be set |
|
|
608 | to the values found I<before> a change was detected, while C<< $w->attr >> |
|
|
609 | returns the values found leading to the change detection. The difference (if any) |
|
|
610 | between C<prev> and C<attr> is what triggered the callback. |
|
|
611 | |
|
|
612 | If you did something to the filesystem object and do not want to trigger |
|
|
613 | yet another change, you can call C<stat> to update EV's idea of what the |
|
|
614 | current attributes are. |
|
|
615 | |
|
|
616 | =item $w->set ($path, $interval) |
|
|
617 | |
|
|
618 | Reconfigures the watcher, see the constructor above for details. Can be |
|
|
619 | called at any time. |
|
|
620 | |
|
|
621 | =item $current_path = $w->path |
|
|
622 | |
|
|
623 | =item $old_path = $w->path ($new_path) |
|
|
624 | |
|
|
625 | Returns the previously set path and optionally set a new one. |
|
|
626 | |
|
|
627 | =item $current_interval = $w->interval |
|
|
628 | |
|
|
629 | =item $old_interval = $w->interval ($new_interval) |
|
|
630 | |
|
|
631 | Returns the previously set interval and optionally set a new one. Can be |
|
|
632 | used to query the actual interval used. |
|
|
633 | |
|
|
634 | =back |
|
|
635 | |
|
|
636 | |
556 | =head3 IDLE WATCHERS - when you've got nothing better to do... |
637 | =head3 IDLE WATCHERS - when you've got nothing better to do... |
557 | |
638 | |
558 | =over 4 |
639 | =over 4 |
559 | |
640 | |
560 | =item $w = EV::idle $callback |
641 | =item $w = EV::idle $callback |
… | |
… | |
646 | |
727 | |
647 | The C<check_ns> variant doesn't start (activate) the newly created watcher. |
728 | The C<check_ns> variant doesn't start (activate) the newly created watcher. |
648 | |
729 | |
649 | =back |
730 | =back |
650 | |
731 | |
651 | =head3 STAT WATCHERS - did the file stats just change? |
|
|
652 | |
732 | |
653 | =over 4 |
733 | =head3 FORK WATCHERS - the audacity to resume the event loop after a fork |
654 | |
734 | |
655 | =item $w = EV::stat $path, $interval, $callback |
735 | Fork watchers are called when a C<fork ()> was detected. The invocation |
|
|
736 | is done before the event loop blocks next and before C<check> watchers |
|
|
737 | are being called, and only in the child after the fork. |
656 | |
738 | |
657 | =item $w = EV::stat_ns $path, $interval, $callback |
739 | =over 4 |
658 | |
740 | |
659 | Call the callback when a file status change has been detected on |
741 | =item $w = EV::fork $callback |
660 | C<$path>. The C<$path> does not need to exist, changing from "path exists" |
|
|
661 | to "path does not exist" is a status change like any other. |
|
|
662 | |
742 | |
663 | The C<$interval> is a recommended polling interval for systems where |
743 | =item $w = EV::fork_ns $callback |
664 | OS-supported change notifications don't exist or are not supported. If |
|
|
665 | you use C<0> then an unspecified default is used (which is highly |
|
|
666 | recommended!), which is to be expected to be around five seconds usually. |
|
|
667 | |
744 | |
668 | This watcher type is not meant for massive numbers of stat watchers, |
745 | Call the callback before the event loop is resumed in the child process |
669 | as even with OS-supported change notifications, this can be |
746 | after a fork. |
670 | resource-intensive. |
|
|
671 | |
747 | |
672 | The C<stat_ns> variant doesn't start (activate) the newly created watcher. |
748 | The C<fork_ns> variant doesn't start (activate) the newly created watcher. |
673 | |
|
|
674 | =item $w->set ($path, $interval) |
|
|
675 | |
|
|
676 | Reconfigures the watcher, see the constructor above for details. Can be |
|
|
677 | called at any time. |
|
|
678 | |
|
|
679 | =item $current_path = $w->path |
|
|
680 | |
|
|
681 | =item $old_path = $w->path ($new_path) |
|
|
682 | |
|
|
683 | Returns the previously set path and optionally set a new one. |
|
|
684 | |
|
|
685 | =item $current_interval = $w->interval |
|
|
686 | |
|
|
687 | =item $old_interval = $w->interval ($new_interval) |
|
|
688 | |
|
|
689 | Returns the previously set interval and optionally set a new one. Can be |
|
|
690 | used to query the actual interval used. |
|
|
691 | |
749 | |
692 | =back |
750 | =back |
693 | |
751 | |
694 | |
752 | |
695 | =head1 THREADS |
753 | =head1 THREADS |
… | |
… | |
726 | |
784 | |
727 | 1; |
785 | 1; |
728 | |
786 | |
729 | =head1 SEE ALSO |
787 | =head1 SEE ALSO |
730 | |
788 | |
731 | L<EV::DNS>. |
789 | L<EV::ADNS> (asynchronous dns), L<Glib::EV> (makes Glib/Gtk2 use EV as |
|
|
790 | event loop), L<Coro::EV> (efficient coroutines with EV). |
732 | |
791 | |
733 | =head1 AUTHOR |
792 | =head1 AUTHOR |
734 | |
793 | |
735 | Marc Lehmann <schmorp@schmorp.de> |
794 | Marc Lehmann <schmorp@schmorp.de> |
736 | http://home.schmorp.de/ |
795 | http://home.schmorp.de/ |