home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Updates / Perl / Non-RPC / !Perl / riscos / RISCOS / DrawFile / OpaqueObject.pm < prev    next >
Text File  |  1999-01-20  |  2KB  |  88 lines

  1. package RISCOS::DrawFile::OpaqueObject;
  2. use Carp;
  3.  
  4. use strict;
  5. use vars qw ($VERSION @ISA);
  6.  
  7. require RISCOS::DrawFile::Object;
  8.  
  9. $VERSION = 0.01;
  10. @ISA = 'RISCOS::DrawFile::Object';
  11.  
  12. ### use SelfLoader;
  13. sub RISCOS::DrawFile::OpaqueObject::new ($$);
  14. sub RISCOS::DrawFile::OpaqueObject::BBox ;
  15. sub RISCOS::DrawFile::OpaqueObject::Size ;
  16. sub RISCOS::DrawFile::OpaqueObject::Pack ;
  17. sub RISCOS::DrawFile::OpaqueObject::Write ;
  18. 1;
  19. ### __DATA__
  20. sub new ($$) {
  21.     my $proto = shift;
  22.     my $class = ref($proto) || $proto;
  23.  
  24.     carp "Cannot make a $proto from a " . ref ($_[0]) if ref ($_[0]);
  25.  
  26.     my ($self, $type) = $class->SUPER::new (@_);
  27.     return $self if ref ($self) eq 'ARRAY';
  28.  
  29.     my ($bbox, $length) = [];
  30.     ($length, @$bbox) = unpack 'x4Ii4', $_[0];
  31.     return undef unless length ($_[0]) == $length or $length & 3;
  32.  
  33.     $self->{'__TYPE'} = $type;
  34.     $self->{'__BBOX'} = $bbox;
  35.     $self->{'__DATA'} = substr $_[0], 24;
  36.     
  37.     wantarray ? ($self, $type) : $self;
  38. }
  39.  
  40. sub BBox {
  41.     my $self = shift;
  42.     $self->{'__BBOX'};
  43. }
  44.  
  45. *BBox_Calc = \&BBox;
  46.  
  47. sub Size {
  48.     my $self = shift;
  49.     24 + length $self->{'__DATA'};
  50. }
  51.  
  52. sub Pack {
  53.     my $self = shift;
  54.     $self->PackTypeSizeBBox() . $self->{'__DATA'};
  55. }
  56.  
  57. # Just in case we have a huge thing
  58. sub Write {
  59.     my $self = shift;
  60.     print {$_[0]} $self->PackTypeSizeBBox(), $self->{'__DATA'};
  61. }
  62.  
  63. 1;
  64. __END__
  65.  
  66. =head1 NAME
  67.  
  68. RISCOS::DrawFile::OpaqueObject
  69.  
  70. =head1 SYNOPSIS
  71.  
  72. Class to handle unrecognised objects in DrawFiles
  73.  
  74. =head1 DESCRIPTION
  75.  
  76. C<RISCOS::DrawFile::OpaqueObject> provides a class that stores any object from
  77. a DrawFile without needing to know its contents. TextAreas, Options, Paths,
  78. Sprites and JPEGs were stored as opaque objects during DrawFile development,
  79. before specific classes were written to manipulate them.
  80.  
  81. =head1 BUGS
  82.  
  83. None known.
  84.  
  85. =head1 AUTHOR
  86.  
  87. Nicholas Clark <F<nick@unfortu.net>>
  88.