File: 03readonly.t

package info (click to toggle)
libobject-pad-classattr-struct-perl 0.06-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 136 kB
  • sloc: perl: 110; makefile: 7; sh: 1
file content (26 lines) | stat: -rw-r--r-- 481 bytes parent folder | download
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
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;

use Object::Pad;
use Object::Pad::ClassAttr::Struct;

class Example :Struct(readonly) {
   field $x;
   field $y;
   field $z = undef;
}

{
   my $obj = Example->new( x => 10, y => 20, z => 30 );
   is( $obj->x, 10, 'Object still has readers' );

   ok( !defined eval { $obj->x = 40 },
      'Failed to set x of readonly struct' );
   is( $obj->x, 10, 'Object unchanged after failed attempt to mutate' );
}

done_testing;