File::...r::Lite(3pm)

πŸ“¦
version 0.652003 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– File::Monitor::Lite β€” monitor file changes πŸ’–

okay bestie, listen. this is File::Monitor::Lite, and it watches your files for you like the loyal little main character it is. it lives in the Perl user-contributed docs section. let's go ✨


🌸 SYNOPSIS 🌸

  use File::Monitor::Lite;

  my $monitor = File::Monitor::Lite->new (
      in => '.',
      name => '*.html',
  );

  while ($monitor->check() and sleep 1){
      my @deleted_files = $monitor->deleted;
      my @modified_files = $monitor->modified;
      my @created_files = $monitor->created;
      my @observing_files = $monitor->observed;
      `do blah..` if $monitor->anychange;
  }

like… that's it. that's the whole vibe. πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so this is another implementation of File::Monitor. here's the tea: File::Monitor cannot detect file creation unless you declare the file name first πŸ™ˆ. so instead, this module uses File::Find::Rule to rescan files every single time $monitor->check() is executed. fr fr. to use it, just follow the synopsis above and you're slaying πŸ’…

currently, you cannot change file observing rules on an existing monitor. to switch things up, you just make another monitor object with new rules. periodt:

  $m1=File::Monitor::Lite->new(
      name => '*.html',
      in => '.',
  );
  $m1->check();
  #blah...
  $m2=File::Monitor::Lite->new(
      name => '*.css',
      in => '.',
  );
  $m2->check();
  #blah...

see? new rules, new object, no drama 🌈


✨ INTERFACE ✨

πŸ’œ " new ( args ) "

creates a brand new File::Monitor::Lite object. iconic behaviour honestly.

    my $monitor = File::Monitor::Lite->new(
        in => '.',
        name => '*.mp3',
    );

the syntax is inherited from File::Find::Rule 🧚 and it gets applied onto File::Find::Rule like this:

    File::Find::Rule
        ->file()
        ->name('*.mp3')
        ->in('.');

and as described in File::Find::Rule, name can be globs or regular expressions β€” literally whatever your heart desires:

    name => '*.pm',                     # a simple glob
    name => qr/.+\.pm$/,                # regex
    name => ['*.mp3', qr/.+\.ogg$/],    # array of rules
    name => @rules,

πŸ’œ " check() "

checks if any file recognized by File::Find::Rule has changed β€” created, modified, or deleted. the usage is giving very simple:

    $monitor->check();

πŸ’œ " created "

returns an array of file names that have been created since the last check 🌱

πŸ’œ " modified "

returns an array of file names that have been modified since the last check ✏️

πŸ’œ " deleted "

returns an array of file names that have been deleted since the last check πŸ’€

πŸ’œ " observed "

returns an array of file names that the monitor is observing at πŸ‘€

ngl, the synopsis also hits us with $monitor->anychange inside that if β€” it's right there in the example, bestie 🫢

πŸŽ€ SEE ALSO πŸŽ€

  • File::Find::Rule
  • File::Monitor

πŸ‘‘ AUTHOR πŸ‘‘

dryman, <idryman@gmail.com> πŸ’Œ


Copyright (C) 2011 by dryman

this library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available. slay ✨


okay that's the whole page, no cap 🫢 this was File::...r::Lite(3pm), from perl v5.34.0, dated 2022-06-13 β€” mwah, go monitor something cute πŸ’…πŸŒΈ

πŸ“¦ where this page comes from