File: extend.t

package info (click to toggle)
librole-tiny-perl 2.002004-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 292 kB
  • sloc: perl: 454; makefile: 2
file content (52 lines) | stat: -rw-r--r-- 1,084 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
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
use strict;
use warnings;
use Test::More;

my %apply_steps;
BEGIN {
  package MyRoleTinyExtension;
  use Role::Tiny ();
  our @ISA = qw(Role::Tiny);

  sub role_application_steps {
    my $self = shift;
    return (
      'role_apply_before',
      $self->SUPER::role_application_steps(@_),
      'Fully::Qualified::role_apply_after',
    );
  };

  sub role_apply_before {
    my ($self, $to, $role) = @_;
    ::ok !Role::Tiny::does_role($to, $role),
      "$role not applied to $to yet";
    $apply_steps{$to}{$role}{before}++;
  }
  sub Fully::Qualified::role_apply_after {
    my ($self, $to, $role) = @_;
    ::ok +Role::Tiny::does_role($to, $role),
      "$role applied to $to";
    $apply_steps{$to}{$role}{after}++;
  }
}

{
  package ExtendedRole;
  MyRoleTinyExtension->import;

  sub added_sub {}
}

{
  package ApplyTo;
  MyRoleTinyExtension->apply_role_to_package(__PACKAGE__, 'ExtendedRole');
}

is $apply_steps{'ApplyTo'}{'ExtendedRole'}{before}, 1,
  'before step was run';

is $apply_steps{'ApplyTo'}{'ExtendedRole'}{after}, 1,
  'after step was run';

done_testing;