home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _61668820a7ae522c43db97fcff04deb8 < prev    next >
Text File  |  2004-06-01  |  5KB  |  188 lines

  1. #---------------------------------------------------------------------
  2. package Win32::ChangeNotify;
  3. #
  4. # Copyright 1998 Christopher J. Madsen
  5. #
  6. # Created: 3 Feb 1998 from the ActiveWare version
  7. #   (c) 1995 Microsoft Corporation. All rights reserved.
  8. #       Developed by ActiveWare Internet Corp., http://www.ActiveWare.com
  9. #
  10. #   Other modifications (c) 1997 by Gurusamy Sarathy <gsar@activestate.com>
  11. #
  12. # Author: Christopher J. Madsen <chris_madsen@geocities.com>
  13. # Version: 1.02 (13-Jun-1999)
  14. #
  15. # This program is free software; you can redistribute it and/or modify
  16. # it under the same terms as Perl itself.
  17. #
  18. # This program is distributed in the hope that it will be useful,
  19. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See either the
  21. # GNU General Public License or the Artistic License for more details.
  22. #
  23. # Monitor directory for changes
  24. #---------------------------------------------------------------------
  25.  
  26. $VERSION = '1.02';
  27.  
  28. use Carp;
  29. use Win32::IPC 1.00 '/./';      # Import everything
  30. require Exporter;
  31. require DynaLoader;
  32.  
  33. @ISA = qw(Exporter DynaLoader Win32::IPC);
  34. # Items to export into callers namespace by default. Note: do not export
  35. # names by default without a very good reason. Use EXPORT_OK instead.
  36. # Do not simply export all your public functions/methods/constants.
  37. @EXPORT = qw(
  38.     FILE_NOTIFY_CHANGE_ATTRIBUTES
  39.     FILE_NOTIFY_CHANGE_DIR_NAME
  40.     FILE_NOTIFY_CHANGE_FILE_NAME
  41.     FILE_NOTIFY_CHANGE_LAST_WRITE
  42.     FILE_NOTIFY_CHANGE_SECURITY
  43.     FILE_NOTIFY_CHANGE_SIZE
  44.     INFINITE
  45. );
  46. @EXPORT_OK = qw(
  47.   wait_all wait_any
  48. );
  49.  
  50. sub AUTOLOAD {
  51.     # This AUTOLOAD is used to 'autoload' constants from the constant()
  52.     # XS function.
  53.  
  54.     my $constname;
  55.     ($constname = $AUTOLOAD) =~ s/.*:://;
  56.     if ($constname =~ /^(?:FILE_NOTIFY_CHANGE_|INFINITE)/) {
  57.     local $! = 0;
  58.         my $val = constant($constname);
  59.         croak("$constname is not defined by Win32::ChangeNotify") if $! != 0;
  60.         eval "sub $AUTOLOAD { $val }";
  61.         goto &$AUTOLOAD;
  62.     }
  63. } # end AUTOLOAD
  64.  
  65. bootstrap Win32::ChangeNotify;
  66.  
  67. sub new {
  68.     my ($class,$path,$subtree,$filter) = @_;
  69.  
  70.     if ($filter =~ /\A[\s|A-Z_]+\Z/i) {
  71.         $filter = 0;
  72.         foreach (split(/[\s|]+/, $_[3])) {
  73.             $filter |= constant("FILE_NOTIFY_CHANGE_" . uc $_);
  74.             carp "Invalid filter $_" if $!;
  75.         }
  76.     }
  77.     _new($class,$path,$subtree,$filter);
  78. } # end new
  79.  
  80. sub Close { &close }
  81.  
  82. sub FindFirst { $_[0] = Win32::ChangeNotify->_new(@_[1..3]); }
  83.  
  84. sub FindNext { &reset }
  85.  
  86. 1;
  87. __END__
  88.  
  89. =head1 NAME
  90.  
  91. Win32::ChangeNotify - Monitor events related to files and directories
  92.  
  93. =head1 SYNOPSIS
  94.  
  95.     require Win32::ChangeNotify;
  96.  
  97.     $notify = Win32::ChangeNotify->new($Path,$WatchSubTree,$Events);
  98.     $notify->wait or warn "Something failed: $!\n";
  99.     # There has been a change.
  100.  
  101. =head1 DESCRIPTION
  102.  
  103. This module allows the user to use a Win32 change notification event
  104. object from Perl.  This allows the Perl program to monitor events
  105. relating to files and directory trees.
  106.  
  107. The C<wait> method and C<wait_all> & C<wait_any> functions are
  108. inherited from the L<"Win32::IPC"> module.
  109.  
  110. =head2 Methods
  111.  
  112. =over 4
  113.  
  114. =item $notify = Win32::ChangeNotify->new($path, $subtree, $filter)
  115.  
  116. Constructor for a new ChangeNotification object.  C<$path> is the
  117. directory to monitor.  If C<$subtree> is true, then all directories
  118. under C<$path> will be monitored.  C<$filter> indicates what events
  119. should trigger a notification.  It should be a string containing any
  120. of the following flags (separated by whitespace and/or C<|>).
  121.  
  122.    ATTRIBUTES    Any attribute change
  123.    DIR_NAME     Any directory name change
  124.    FILE_NAME    Any file name change (creating/deleting/renaming)
  125.    LAST_WRITE   Any change to a file's last write time
  126.    SECURITY     Any security descriptor change
  127.    SIZE         Any change in a file's size
  128.  
  129. (C<$filter> can also be an integer composed from the
  130. C<FILE_NOTIFY_CHANGE_*> constants.)
  131.  
  132. =item $notify->close
  133.  
  134. Shut down monitoring.  You could just C<undef $notify> instead (but
  135. C<close> works even if there are other copies of the object).  This
  136. happens automatically when your program exits.
  137.  
  138. =item $notify->reset
  139.  
  140. Resets the ChangeNotification object after a change has been detected.
  141. The object will become signalled again after the next change.  (It is
  142. OK to call this immediately after C<new>, but it is not required.)
  143.  
  144. =item $notify->wait
  145.  
  146. See L<"Win32::IPC">.  Remember to call C<reset> afterwards if you want
  147. to continue monitoring.
  148.  
  149. =back
  150.  
  151. =head2 Deprecated Functions and Methods
  152.  
  153. B<Win32::ChangeNotify> still supports the ActiveWare syntax, but its
  154. use is deprecated.
  155.  
  156. =over 4
  157.  
  158. =item FindFirst($Obj,$PathName,$WatchSubTree,$Filter)
  159.  
  160. Use
  161.  
  162.   $Obj = Win32::ChangeNotify->new($PathName,$WatchSubTree,$Filter)
  163.  
  164. instead.
  165.  
  166. =item $obj->FindNext()
  167.  
  168. Use C<$obj-E<gt>reset> instead.
  169.  
  170. =item $obj->Close()
  171.  
  172. Use C<$obj-E<gt>close> instead.
  173.  
  174. =back
  175.  
  176. =head1 AUTHOR
  177.  
  178. Christopher J. Madsen E<lt>F<chris_madsen@geocities.com>E<gt>
  179.  
  180. Loosely based on the original module by ActiveWare Internet Corp.,
  181. F<http://www.ActiveWare.com>
  182.  
  183. =cut
  184.  
  185. # Local Variables:
  186. # tmtrack-file-task: "Win32::ChangeNotify"
  187. # End:
  188.