| 1 | package POE::Component::DirWatch::Role::Signatures; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 3 | ▶ | use POE; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 3 | ▶ | use Moose::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 3 | ▶ | use File::Signature; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 3 | our $VERSION = "0.300001"; | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | has signatures => ( | ||||||||||||||||||||
| 10 | is => 'ro', | ||||||||||||||||||||
| 11 | isa => 'HashRef', | ||||||||||||||||||||
| 12 | required => 1, | ||||||||||||||||||||
| 13 | 2 | ▶ | default => sub { {} } | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 3 | ); | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | after _file_callback => sub { | ||||||||||||||||||||
| 17 | 12 | ▶ | my ($self, $file) = @_[OBJECT, ARG0]; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||
| 18 | 12 | ▶ | $self->signatures->{ "$file" } ||= $self->_generate_signature($file); | ||||||||||||||||||
|
Condition66%2/3
$self->signatures->{"$file"} ||= $self->_generate_signature($file)
MC/DC0%0/2
$self->signatures->{"$file"} ||= $self->_generate_signature($file)
$self->signatures->{"$file"}
$self->_generate_signature($file)
Truth table66%2/3
A ||= B
A= $self->signatures->{"$file"}B= $self->_generate_signature($file)
| |||||||||||||||||||||
| 19 | 3 | }; | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | before _poll => sub { | ||||||||||||||||||||
| 22 | 6 | ▶ | my $sigs = shift->signatures; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 23 | 6 | delete($sigs->{$_}) for grep {! -e $_ } keys %$sigs; | |||||||||||||||||||
| 24 | 3 | }; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | sub _generate_signature{ | ||||||||||||||||||||
| 27 | 10 | ▶ | my ($self, $file) = @_; | ||||||||||||||||||
|
Subroutine
_generate_signature: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 28 | 10 | return "" . File::Signature->new( "$file" ) . ""; | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 3 | 1; | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | __END__; | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | #--------#---------#---------#---------#---------#---------#---------#--------- | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | =head1 NAME | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | POE::Component::DirWatch::Role::Signatures | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | =head1 DESCRIPTION | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | POE::Component::DirWatch::Role::Signatures is a role which provides | ||||||||||||||||||||
| 45 | L<File::Signature> functionality to DirWatch-based classes. It will keep a | ||||||||||||||||||||
| 46 | hashref of signatures of the files processing to allow you to determine if | ||||||||||||||||||||
| 47 | a file has changed. | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | =head1 ATTRIBUTES | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | =head2 signatures | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | Read-write. Will return a hashref in which keys will be the full path of the | ||||||||||||||||||||
| 54 | files seen and the value will be a stringified L<File::Signature> object. | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | =head1 METHODS | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | =head2 file_callback | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | C<after '_file_callback'> Add the file's signature to C<signatures> if it | ||||||||||||||||||||
| 61 | doesnt yet exist. | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | =head2 _poll | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | C<before '_poll'> the list of known files is checked and if any of the files no | ||||||||||||||||||||
| 66 | longer exist they are removed from the list of known files. | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | =head1 SEE ALSO | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | L<File::Signature>, L<POE::Component::DirWatch>, L<Moose> | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | =head1 COPYRIGHT | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | Copyright 2006-2008 Guillermo Roditi. This is free software; you may | ||||||||||||||||||||
| 75 | redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | =cut | ||||||||||||||||||||
| 78 | |||||||||||||||||||||