home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Updates / Perl / Non-RPC / !Perl / riscos / RISCOS / Chunk.pm < prev    next >
Text File  |  1998-07-31  |  2KB  |  118 lines

  1. package RISCOS::Chunk;
  2.  
  3. use Carp;
  4.  
  5. use strict;
  6. use vars qw (@ISA $VERSION);
  7.  
  8. $VERSION = 0.02;
  9. @ISA = qw();
  10.  
  11. sub new {
  12.     my $proto = shift;
  13.     my $class = ref($proto) || $proto;
  14.     my $self  = {};
  15.     $self->{__ID} = shift;
  16.     $self->{__DATA} = shift;
  17.     
  18.     my $length = shift;
  19.  
  20.     my $index = shift;
  21.     $self->{__INDEX} = $index if defined $index;
  22.     my $offset = shift;
  23.     $self->{__OFFSET} = $offset if defined $offset;
  24.  
  25.     if (defined $length) {
  26.     carp "Chunk size mismatch - expected $length, got "
  27.       . length $self->{__DATA} unless $length == length $self->{__DATA};
  28.     }
  29.  
  30.     bless ($self, $class);
  31. }
  32.  
  33. sub ID {
  34.     my $self = shift;
  35.     $self->{'__ID'};
  36. }
  37.  
  38. sub Data {
  39.     my $self = shift;
  40.     $self->{'__DATA'};
  41. }
  42.  
  43. sub Length {
  44.     my $self = shift;
  45.     length $self->{'__DATA'};
  46. }
  47.  
  48. sub Index {
  49.     my $self = shift;
  50.     $self->{'__INDEX'};
  51. }
  52.  
  53. sub Offset {
  54.     my $self = shift;
  55.     $self->{'__OFFSET'};
  56. }
  57.  
  58. 1;
  59. __END__
  60.  
  61. =head1 NAME
  62.  
  63. RISCOS::Chunk -- manipulate Chunks in Acorn Chunkfiles
  64.  
  65. =head1 SYNOPSIS
  66.  
  67.     use RISCOS::Chunk;
  68.     
  69.     $chunk = new RISCOS::Chunk $chunkid, substr ($file, $offset, $size), $size,
  70.                    $index, $offset;
  71.  
  72. =head1 DESCRIPTION
  73.  
  74. C<RISCOS::Chunk> provides a class to hold details about a chunk in a chunkfile.
  75.  
  76. =head2 Methods
  77.  
  78. =over 4
  79.  
  80. =item new <ID>, <data>, [<length>, [<index>, [<offset>]]]
  81.  
  82. Returns a new C<RISCOS::Chunk> object with a ChunkID I<ID>, and contents
  83. I<data>. If <length> is defined it is checked against C<length I<data>>. The
  84. I<index> of the chunk in the chunkfile header and the I<offset> of the chunk
  85. data in the chunkfile are stored if supplied.
  86.  
  87. =item ID
  88.  
  89. Returns the chunk ID.
  90.  
  91. =item Data
  92.  
  93. Returns the chunk data.
  94.  
  95. =item Length
  96.  
  97. Returns the length of the chunk data - I<i.e.> literally C<length Data()>
  98.  
  99. =item Index
  100.  
  101. Returns the index of the chunk in the chunkfile header (if known, else returns
  102. undefined);
  103.  
  104. =item Offset
  105.  
  106. Returns the offset of the chunk data in the chunkfile (if known, else returns
  107. undefined);
  108.  
  109. =back
  110.  
  111. =head1 BUGS
  112.  
  113. None known.
  114.  
  115. =head1 AUTHOR
  116.  
  117. Nicholas Clark <F<nick@unfortu.net>>
  118.