b0VIM 7.2X|M" $rclrcl-desktop~rcl/perl/Varnish-CLI/lib/Varnish/CLI.pmutf-8 3210#"! Utp|} ad|gfWVIHCB+*)K ~ X W ^  } k j ?  _ 7 ` _ 4 dc8 ]+*c?rqJ"^.|VU.lkjON?>======cutConnect to the Varnish CLI interface=head2 connect=head1 SUBROUTINES/METHODS ); isa => 'Int',has last_status => ( is => 'rw', default => sub{ [] } ); isa => 'ArrayRef',has last_lines => ( is => 'rw', required => 1 ); default => 0, isa => 'Int',has connected => ( is => 'rw', clearer => 'clear_t' ); isa => 'Net::Telnet',has t => ( is => 'rw', isa => 'Str' );has secret => ( is => 'rw', default => 1 ); required => 1, isa => 'Int',has timeout => ( is => 'rw', default => 6082 ); required => 1, isa => 'Int',has port => ( is => 'ro', default => 'localhost' ); required => 1, isa => 'Str',has host => ( is => 'ro',=cut ); isa => 'Int', has last_status => ( is => 'rw', default => sub{ [] } ); isa => 'ArrayRef', has last_lines => ( is => 'rw', required => 1 ); default => 0, isa => 'Int', has connected => ( is => 'rw', isa => 'Str' ); has secret => ( is => 'rw', clearer => 'clear_t' ); isa => 'Net::Telnet', has t => ( is => 'rw', default => 1 ); required => 1, isa => 'Int', has timeout => ( is => 'rw', default => 6082 ); required => 1, isa => 'Int', has port => ( is => 'ro', default => 'localhost' ); required => 1, isa => 'Str', has host => ( is => 'ro',=head1 PROPERTIES my $varnish = Varnish::CLI->new( secret => $secret );Remember - complete contents of the secret file (including a newline if it exists!)of your secret file, otherwise authentication will fail... Makes sense!! :)If you have started your Varnish CLI with a secret, you must will have to pass the contents my $varnish = Varnish::CLI->new();Varnish settings:The Varnish::CLI can be initialised without any parameters, and will usually work for the default $varnish->send( 'url.purge .*' ); ); secret => $secret, timeout => $timeout, port => $port, my $varnish = Varnish::CLI->new( host => $host, use Varnish::CLI;This module allows easy script interface to it.Varnish CLI is a great administration tool, but a bit difficult to script for.=head1 SYNOPSISour $VERSION = '0.03';=cutVersion 0.03=head1 VERSIONVarnish::CLI - An interface to the Varnish CLI=head1 NAMEuse Digest::SHA qw/sha256_hex/;use Carp;use Net::Telnet;use Moose;package Varnish::CLI;adn wvUT76ON 1; # End of Varnish=cutSee http://dev.perl.org/licenses/ for more information.by the Free Software Foundation; or the Artistic License.under the terms of either: the GNU General Public License as publishedThis program is free software; you can redistribute it and/or modify itCopyright 2011 Robin Clarke.=head1 LICENSE AND COPYRIGHTL=head1 ACKNOWLEDGEMENTS=backL=item * Search CPANLad= xwSR==item * CPAN RatingsL=item * AnnoCPAN: Annotated CPAN documentationL=item * RT: CPAN's request trackeradwEm\>= I ? 6 t K    < 6 ( & %   T B < $ g Q   w#|fN0~}wbN7 hE#YFE,+vRQ<=item * CPAN RatingsL=item * AnnoCPAN: Annotated CPAN documentationL=item * Repository on Github=over 4You can also look for information at: perldoc Varnish::CLIYou can find documentation for this module with the perldoc command.=head1 SUPPORTautomatically be notified of progress on your bug as I make changes.the web interface at L. I will be notified, and then you'llPlease report any bugs or feature requests to C, or through=head1 BUGSRobin Clarke, C<< >>=head1 AUTHOR} $self->last_status( $status ); $self->last_lines( \@lines ); push( @lines, $t->getline() ); # There's always one empty line after } $got_chars += length( $lines[-1] ); push( @lines, $t->getline() ); while( $got_chars < $chars ){ my @lines; $self->connected( 1 ); my $got_chars = 0; my $chars = $2; my $status = $1; } croak( "Unexpected line:\n($line)" ); print $t->getline(); print "Next line:\n"; $self->connected( 0 ); if( $line !~ m/^(\d+)\s*(\d+)\s*$/ ){ my $line = $t->getline(); my $t = $self->t(); my $self = shift;sub _parse_response{# Private method to parse the response from the CLI} } "Last lines: \n\t" . join( "\t", @{ $self->last_lines() } ) . "\n" ); croak( "Command failed: $command\nStatus: " . $self->last_status() . "\n". if( $self->last_status() != 200 ){ $self->_parse_response(); $self->t->print( $command ); $self->connect(); # Make sure we're connected } croak( "Cannot call send without a command" ); if( ! $command ){ my( $self, $command ) = @_;sub send{=cutSend a command to the Varnish CLi=head2 send} $self->connected( 0 ); $self->clear_t(); $t->close(); $t->print( 'quit' ); my $t = $self->t(); } return 1; carp( "Close called, but not connected" ); if( not $self->t() or not $self->connected() ){ my( $self ) = shift;sub close{=cutClose the connection to the Varnish CLI interface=head2 close} return 1; } "Last lines: \n\t" . join( "\t", @{ $self->last_lines() } ) . "\n" ); croak( "Connection failed\nStatus: " . $self->last_status() . "\n". if( $self->last_status() != 200 ){ } } croak( "Authentication failed!\n" ); if( $self->last_status != 200 ){ $self->send( "auth $auth" ); my $auth = sha256_hex( $challenge . "\n" . $self->secret() . $challenge . "\n" ); my $challenge = substr( $self->last_lines()->[0], 0, 32 ); } croak( "Connection failed: authentication required, but no secret given\n" ); if( not $self->secret() ){ if( $self->last_status() == 107 ){ # A 107 response on connection means the Varnish CLI expects authentication $self->_parse_response(); $t->open(); $self->t( $t ); ); Input_record_separator => "\n", Output_record_separator => "\n", Timeout => $self->timeout(), Port => $self->port(), Host => $self->host(), my $t = Net::Telnet->new( } return 1; if( $self->t() and $self->connected() ){ my( $self ) = shift;sub connect{