File: Event.pm

package info (click to toggle)
libfile-changenotify-perl 0.31-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 356 kB
  • sloc: perl: 1,626; makefile: 8
file content (171 lines) | stat: -rw-r--r-- 3,568 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package File::ChangeNotify::Event;

use strict;
use warnings;
use namespace::autoclean;

our $VERSION = '0.31';

use Types::Standard qw( ArrayRef HashRef Str );
use Type::Utils qw( enum );

use Moo;

has path => (
    is       => 'ro',
    isa      => Str,
    required => 1,
);

has type => (
    is       => 'ro',
    isa      => enum( [qw( create modify delete unknown )] ),
    required => 1,
);

has attributes => (
    is        => 'ro',
    isa       => ArrayRef [HashRef],
    predicate => 'has_attributes',
);

has content => (
    is        => 'ro',
    isa       => ArrayRef,
    predicate => 'has_content',
);

__PACKAGE__->meta->make_immutable;

1;

# ABSTRACT: Class for file change events

__END__

=pod

=encoding UTF-8

=head1 NAME

File::ChangeNotify::Event - Class for file change events

=head1 VERSION

version 0.31

=head1 SYNOPSIS

    my $watcher = File::ChangeNotify->instantiate_watcher(
        directories => [ '/my/path', '/my/other' ],
        filter      => qr/\.(?:pm|conf|yml)$/,
        exclude => [ 't', 'root', qr(/(?!\.)[^/]+$) ],
    );

    for my $event ( $watcher->new_events ) {
        print $event->path, ' - ', $event->type, "\n";
    }

=head1 DESCRIPTION

This class provides information about a change to a specific file or
directory.

=head1 METHODS

=head2 File::ChangeNotify::Event->new(...)

This method creates a new event. It accepts the following arguments:

=over 4

=item * path => $path

The full path to the file or directory that changed.

=item * type => $type

The type of event. This must be one of "create", "modify", "delete", or
"unknown".

=back

=head2 $event->path

Returns the path of the changed file or directory.

=head2 $event->type

Returns the type of event.

=head2 $event->has_attributes

This returns true for modify events which include information about a path's
attribute changes.

=head2 $event->attributes

If the event includes information about changes to a path's attributes, then
this returns a two-element arrayref. Each element is in turn a hashref which
will contain at least one of the following keys:

=over 4

=item * permissions

The permissions mask for the path.

=item * uid

The user id that owns the path.

=item * gid

The group id that owns the path.

=back

Note that only keys which changed will be included.

=head2 $event->has_content

This returns true for modify events which include information about a file's
content.

=head2 $event->content

This returns a two-element arrayref where the first element is the old content
and the second is the new content.

B<Note that this content is stored as bytes, not UTF-8. You will need to
explicitly call C<Encode::decode> on the content to make it UTF-8.> This is
done because there's no reason you couldn't use this feature with file's
containing any sort of binary data.

=head1 SUPPORT

Bugs may be submitted at L<http://rt.cpan.org/Public/Dist/Display.html?Name=File-ChangeNotify> or via email to L<bug-file-changenotify@rt.cpan.org|mailto:bug-file-changenotify@rt.cpan.org>.

I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>.

=head1 SOURCE

The source code repository for File-ChangeNotify can be found at L<https://github.com/houseabsolute/File-ChangeNotify>.

=head1 AUTHOR

Dave Rolsky <autarch@urth.org>

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2009 - 2019 by Dave Rolsky.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)

The full text of the license can be found in the
F<LICENSE> file included with this distribution.

=cut