/lib/SDLx/Surface/TiedMatrix.pm

http://github.com/PerlGameDev/SDL · Perl · 38 lines · 31 code · 7 blank · 0 comment · 0 complexity · c6cbe872e7966aaa96d3420d4420f13c MD5 · raw file

  1. package SDLx::Surface::TiedMatrix;
  2. use strict;
  3. use warnings;
  4. use SDLx::Surface::TiedMatrixRow;
  5. use base 'Tie::Array';
  6. our $VERSION = 2.548;
  7. sub new {
  8. my $class = shift;
  9. my $matrix = shift;
  10. my $self = {
  11. matrix => $matrix,
  12. rows => [],
  13. };
  14. return bless $self, $class;
  15. }
  16. sub TIEARRAY {
  17. return SDLx::Surface::TiedMatrix->new( $_[1] );
  18. }
  19. sub FETCH {
  20. my ( $self, $y ) = @_;
  21. unless ( $self->{rows}[$y] ) {
  22. tie my @row, 'SDLx::Surface::TiedMatrixRow', $self->{matrix}, $y;
  23. $self->{rows}[$y] = \@row;
  24. }
  25. return $self->{rows}[$y];
  26. }
  27. sub FETCHSIZE {
  28. my ( $self, $x ) = @_;
  29. return $self->{matrix}->surface->h;
  30. }
  31. 1;