Full/Role.pm

filter: Statementstmt 33.3% 1 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 50.0% 2 / 4 CC 1 SCAR 2.6
CC
1
Cov
33%
BEGIN
1.3
CRAP 1.3
« Full/Class.pm ↑ Summary Full/Script.pm »
1 package Full::Role;
2  
3 0 ▶use Full::Pragmata qw(:v1);
Subroutine BEGIN: called CC=1 SCAR=2.6
4 use parent qw(Full::Pragmata);
5  
6 our $VERSION = '1.004'; # VERSION
7 our $AUTHORITY = 'cpan:TEAM'; # AUTHORITY
8  
9 =encoding utf8
10  
11 =head1 NAME
12  
13 Full::Role - common pragmata for modules which provide an OO rôle
14  
15 =head1 SYNOPSIS
16  
17 package Example::Role;
18 use Full::Role qw(:v1);
19  
20 method example;
21  
22 1;
23  
24 =head3 Method parameter constraints
25  
26 These use L<Signature::Attribute::Checked> to provide method parameter checks.
27 Note that the C<extended> keyword is required, see L<Sublike::Extended> for more information.
28  
29 package Example;
30 use Full::Role qw(:v1);
31 extended method example ($v :Checked(Num)) { }
32  
33 =head2 Class features
34  
35 The calling package will be marked as an L<Object::Pad> rôle, providing the
36 L<Object::Pad/method>, L<Object::Pad/has> and C<async method> keywords, among others.
37  
38 This also makes available a L<Log::Any> instance in the C<$log> package variable,
39 and for L<OpenTelemetry> support you get C<$tracer> as an L<OpenTelemetry>
40 instance.
41  
42 It's very likely that future versions will bring in new functionality or
43 enable/disable a different featureset. This behaviour will be controlled through
44 version tags:
45  
46 use Full::Class qw(:v1);
47  
48 The latest available version is C<:v1>.
49  
50 =cut
51  
52 use Object::Pad;
53 use Object::Pad qw(:experimental(mop));
54  
55 sub import ($called_on, $version, %args) {
56 my $class = __PACKAGE__;
57 my $pkg = $args{target} // caller(0);
58  
59 $class->next::method($version, target => $pkg);
60 if(my $class = $args{class} // $pkg) {
61 Object::Pad->import_into($pkg, ":experimental(init_expr mop custom_field_attr)");
62  
63 my $method = 'begin_' . ($args{type} || 'role');
64 Module::Load::load($args{extends}) if $args{extends};
65 my $meta = Object::Pad::MOP::Class->$method(
66 $class,
67 (
68 $args{extends}
69 ? (extends => $args{extends})
70 : ()
71 ),
72 );
73 $args{does} = [ $args{does} // () ] unless ref $args{does};
74 for my $role ($args{does}->@*) {
75 Module::Load::load($role) unless eval { Object::Pad::MOP::Class->for_class($role) };
76 $meta->add_role($role);
77 }
78 return $meta;
79 }
80 return $pkg;
81 }
82  
83 1;
84  
85 __END__
« Full/Class.pm ↑ Summary Full/Script.pm »