File: 07subclass-foreign-ARRAY.t

package info (click to toggle)
libobject-pad-perl 0.821-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 936 kB
  • sloc: ansic: 3,361; perl: 3,328; pascal: 28; makefile: 3
file content (57 lines) | stat: -rw-r--r-- 1,139 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl

use v5.18;
use warnings;

use Test2::V0;

use Object::Pad 0.800;

package Base::Class {
   sub new {
      my $class = shift;
      my ( $ok ) = @_;
      ::is( $ok, "ok", '@_ to Base::Class::new' );
      ::is( scalar @_, 1, 'scalar @_ to Base::Class::new' );

      return bless [ 123 ], $class;
   }

   sub fields {
      my $self = shift;
      return "base_field=$self->[0]"
   }
}

class Derived::Class {
   inherit Base::Class;

   field $derived_field = 456;

   BUILD {
      my @args = @_;
      ::is( \@args, [ "ok" ], '@_ to Derived::Class::BUILD' );
   }

   method fields {
      return $self->SUPER::fields . ",derived_field=$derived_field";
   }
}

{
   my $obj = Derived::Class->new( "ok" );
   is( $obj->fields, "base_field=123,derived_field=456",
      '$obj->fields' );

   # We don't mind what the output here is but it should be well-behaved
   # and not crash the dumper
   use Data::Dumper;

   local $Data::Dumper::Sortkeys = 1;

   is( Dumper($obj) =~ s/\s+//gr,
      q($VAR1=bless([123],'Derived::Class');),
      'Dumper($obj) of Object::Pad-extended blessed ARRAY class' );
}

done_testing;