1Dist::Zilla::Role::FileU:s:eCrhaCnognetNroiDtbiiusfttie:cd:aZtPiielorlnla(:3D:)oRcoulmee:n:tFaitlieo:n:ChangeNotification(3)
2
3
4

NAME

6       Dist::Zilla::Role::File::ChangeNotification - Receive notification when
7       something changes a file's contents
8

VERSION

10       version 0.006
11

SYNOPSIS

13           package Dist::Zilla::Plugin::MyPlugin;
14           sub some_phase
15           {
16               my $self = shift;
17
18               my ($source_file) = grep { $_->name eq 'some_name' } @{$self->zilla->files};
19               # ... do something with this file ...
20
21               Dist::Zilla::Role::File::ChangeNotification->meta->apply($source_file);
22               my $plugin = $self;
23               $file->on_changed(sub {
24                   $plugin->log_fatal('someone tried to munge ', shift->name,
25                       ' after we read from it. You need to adjust the load order of your plugins.');
26               });
27               $file->watch_file;
28           }
29

DESCRIPTION

31       This is a role for Dist::Zilla::Role::File objects which gives you a
32       mechanism for detecting and acting on files changing their content.
33       This is useful if your plugin performs an action based on a file's
34       content (perhaps copying that content to another file), and then later
35       in the build process, that source file's content is later modified.
36

METHODS

38   "on_changed($subref)"
39       Provide a method to be invoked against the file when the file's content
40       has changed.  The new file content is passed as an argument.  If you
41       need to do something in your plugin at this point, define the sub as a
42       closure over your plugin object, as demonstrated in the "SYNOPSIS".
43
44       Be careful of infinite loops, which can result if your sub changes the
45       same file's content again! Add a mechanism to return without altering
46       content if particular conditions are met (say that the needed content
47       is already present, or even the value of a particular suitably-scoped
48       variable.
49

METHODS

51   "watch_file"
52       Once this method is called, every subsequent change to the file's
53       content will result in your "on_changed" sub being invoked against the
54       file.  The new content is passed as the argument to the sub; the return
55       value is ignored.
56

SUPPORT

58       Bugs may be submitted through the RT bug tracker
59       <https://rt.cpan.org/Public/Dist/Display.html?Name=Dist-Zilla-Role-
60       FileWatcher> (or bug-Dist-Zilla-Role-FileWatcher@rt.cpan.org
61       <mailto:bug-Dist-Zilla-Role-FileWatcher@rt.cpan.org>).  I am also
62       usually active on irc, as 'ether' at "irc.perl.org".
63

SEE ALSO

65       •   Dist::Zilla::Role::FileWatcher - in this distribution, for
66           providing an interface for a plugin to watch a file
67
68       •   Dist::Zilla::File::OnDisk
69
70       •   Dist::Zilla::File::InMemory
71

AUTHOR

73       Karen Etheridge <ether@cpan.org>
74
76       This software is copyright (c) 2013 by Karen Etheridge.
77
78       This is free software; you can redistribute it and/or modify it under
79       the same terms as the Perl 5 programming language system itself.
80
81
82
83perl v5.36.0                    Di2s0t2:2:-Z0i7l-l2a2::Role::File::ChangeNotification(3)
Impressum