home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / Comp.pm < prev    next >
Encoding:
Perl POD Document  |  2001-04-24  |  3.2 KB  |  119 lines

  1. # $Id: Comp.pm,v 1.5 2001/04/18 06:36:57 btrott Exp $
  2.  
  3. package Net::SSH::Perl::Comp;
  4.  
  5. use strict;
  6. use Carp qw( croak );
  7.  
  8. use vars qw( %COMP );
  9. %COMP = (
  10.     'zlib' => 'Zlib',
  11. );
  12.  
  13. sub new {
  14.     my $class = shift;
  15.     my $type = shift;
  16.     return if $type eq 'none';
  17.     my $comp_class = join '::', __PACKAGE__, $COMP{$type} || $type;
  18.     eval "use $comp_class;";
  19.     my $comp = bless {}, $comp_class;
  20.     $comp->init(@_) if @_;
  21.     $comp;
  22. }
  23.  
  24. sub enabled { $_[0]->{enabled} }
  25. sub enable { $_[0]->{enabled} = 1 }
  26.  
  27. sub init { }
  28.  
  29. sub compress { $_[0] }
  30. sub uncompress { $_[0] }
  31.  
  32. 1;
  33. __END__
  34.  
  35. =head1 NAME
  36.  
  37. Net::SSH::Perl::Comp - Compression/Decompression base class
  38.  
  39. =head1 SYNOPSIS
  40.  
  41.     use Net::SSH::Perl::Comp;
  42.     my $comp = Net::SSH::Perl::Comp->new( $comp_type );
  43.     $comp->compress($data);
  44.  
  45. =head1 DESCRIPTION
  46.  
  47. I<Net::SSH::Perl::Comp> is a base class for compression/decompression
  48. classes. Currently the only such class is the Zlib implementation
  49. (using I<Compress::Zlib>), which is the class I<Net::SSH::Perl::Comp::Zlib>.
  50.  
  51. Each compression object generally has its own internal "state"; this
  52. state changes when you compress or decompress data. The SSH protocol
  53. dictates that you must have two I<separate> objects to compress and
  54. decompress data: one for compression, one for decompression. So, for
  55. example, you would create two I<Net::SSH::Perl::Comp> objects:
  56.  
  57.     my $in = Net::SSH::Perl::Comp->new('Zlib');
  58.     my $inflated = $in->decompress($data);
  59.  
  60.     my $out = Net::SSH::Perl::Comp->new('Zlib');
  61.     my $deflated = $out->compress($data);
  62.  
  63. =head1 USAGE
  64.  
  65. =head2 $comp = Net::SSH::Perl::Comp->new( $comp_type [, @args ] )
  66.  
  67. Constructs a new compression object of compression type I<$comp_type>
  68. and returns that object.
  69.  
  70. If I<@args> are provided, the class's I<init> method is called with
  71. those arguments, for any post-creation initialization.
  72.  
  73. =head2 $comp->init($level)
  74.  
  75. Initializes I<$comp> and sets the compression level to I<$level>.
  76. This method will be called automatically from I<new> if you've
  77. provided I<@args> to I<new>. So, for example, you could write:
  78.  
  79.     my $comp = Net::SSH::Perl::Comp->new('Zlib', 5);
  80.  
  81. To create a new I<Zlib> compression object and initialize its
  82. compression level to 5.
  83.  
  84. =head2 $comp->compress( $data )
  85.  
  86. Compresses I<$data> using the underlying compression mechanism;
  87. returns the compressed data.
  88.  
  89. =head2 $comp->decompress( $data )
  90.  
  91. Decompresses I<$data> using the underlying decompression mechanism;
  92. returns the decompressed data.
  93.  
  94. =head2 $comp->enable
  95.  
  96. "Enables" the compression object. This is useful in the context of
  97. the key exchange (I<Kex>) classes, which create a new compression
  98. object during key negotiation, but don't actually turn it on ("enable"
  99. it) until receiving/sending the I<SSH2_MSG_NEWKEYS> message.
  100.  
  101. I<Net::SSH::Perl::Comp> objects (and subclasses) are disabled by
  102. default.
  103.  
  104. =head2 $comp->enabled
  105.  
  106. Returns the state of the "enabled" flag, ie. whether the compression
  107. object is "turned on".
  108.  
  109. This is used by I<Net::SSH::Perl::Packet> when determining whether
  110. data it receives/sends to the server should be decompressed/compressed,
  111. respectively.
  112.  
  113. =head1 AUTHOR & COPYRIGHTS
  114.  
  115. Please see the Net::SSH::Perl manpage for author, copyright,
  116. and license information.
  117.  
  118. =cut
  119.