| HTTP-Proxy-GreaseMonkey documentation | Contained in the HTTP-Proxy-GreaseMonkey distribution. |
HTTP::Proxy::GreaseMonkey::ScriptHome - A directory of GreaseMonkey scripts
This document describes HTTP::Proxy::GreaseMonkey::ScriptHome version 0.05
use HTTP::Proxy::GreaseMonkey::ScriptHome;
Represents a directory containing a number of GreaseMonkey user scripts.
add_dirAdd a directory that may contain user scripts. The directory will be scanned recursively looking for files with the '.js' extension.
beginBegin filter processing. Rescans script directories adding / removing / updating scripts as appropriate.
HTTP::Proxy::GreaseMonkey::ScriptHome requires no configuration files or environment variables.
None.
None reported.
No bugs have been reported.
Please report any bugs or feature requests to
bug-http-proxy-greasemonkey@rt.cpan.org, or through the web interface at
http://rt.cpan.org.
Andy Armstrong <andy@hexten.net>
Copyright (c) 2007, Andy Armstrong <andy@hexten.net>.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
| HTTP-Proxy-GreaseMonkey documentation | Contained in the HTTP-Proxy-GreaseMonkey distribution. |
package HTTP::Proxy::GreaseMonkey::ScriptHome; use warnings; use strict; use Carp; use File::Find; use HTTP::Proxy::GreaseMonkey::Script; use base qw( HTTP::Proxy::GreaseMonkey );
our $VERSION = '0.05';
sub add_dir { my $self = shift; push @{ $self->{dirs} }, @_; }
sub begin { my ( $self, $message ) = @_; $self->_reload; $self->SUPER::begin( $message ); } sub _reload { my $self = shift; # Invasive superclass surgery follows. Look away if squeamish. my @files = $self->_walk; my @current = @{ $self->{script} || [] }; $self->{script} = []; # Loop over all found scripts replacing any that have been updated, # removing any that have been deleted, adding any that are new, # maintaining original order. while ( my $f = shift @files ) { while ( @current && $f gt $current[0]->file ) { # Delete orphan shift @current; } if ( @current && $f eq $current[0]->file ) { # Match: updated? my $cur = shift @current; my @nstat = stat $f or croak "Can't stat $f ($!)"; my @ostat = $cur->stat; # If the script file hasn't changed recycle the current # script object else replace it with a new one. $self->add_script( $nstat[9] > $ostat[9] ? $f : $cur ); print "Reloading $f\n" if $self->verbose && $nstat[9] > $ostat[9]; } else { # New script $self->add_script( $f ); print "Loading $f\n" if $self->verbose; } } } sub _walk { my $self = shift; my @files = (); find( { wanted => sub { push @files, $_ if -f && /[.]js$/i; }, no_chdir => 1, }, @{ $self->{dirs} || [] } ); return sort @files; } 1; __END__