Full/Class.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
↑ Summary Full/Role.pm »
1 package Full::Class;
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::Class - common pragmata for modules which provide an OO class
14  
15 =head1 SYNOPSIS
16  
17 package Example::Class;
18 use Full::Class qw(:v1);
19  
20 async method startup {
21 $log->infof('Starting %s', __PACKAGE__);
22 }
23  
24 1;
25  
26 =head3 Method parameter constraints
27  
28 These use L<Signature::Attribute::Checked> to provide method parameter checks.
29 Note that the C<extended> keyword is required, see L<Sublike::Extended> for more information.
30  
31 package Example;
32 use Full::Class qw(:v1);
33 extended method example ($v :Checked(Num)) { }
34  
35 =head2 Class features
36  
37 The calling package will be marked as an L<Object::Pad> class, providing the
38 L<Object::Pad/method>, L<Object::Pad/has> and C<async method> keywords.
39  
40 This also makes available a L<Log::Any> instance in the C<$log> package variable,
41 and for L<OpenTelemetry> support you get C<$tracer> as an L<OpenTelemetry>
42 instance.
43  
44 It's very likely that future versions will bring in new functionality or
45 enable/disable a different featureset. This behaviour is controlled through
46 mandatory version tags:
47  
48 use Full::Class qw(:v1);
49  
50 The latest available version is C<:v1>.
51  
52 =cut
53  
54 use Object::Pad;
55 use Object::Pad qw(:experimental(mop));
56  
57 sub import ($called_on, $version, %args) {
58 my $class = __PACKAGE__;
59 my $pkg = $args{target} // caller(0);
60  
61 $class->next::method($version, target => $pkg);
62 if(my $class = $args{class} // $pkg) {
63 Object::Pad->import_into($pkg, ":experimental(init_expr mop custom_field_attr)");
64  
65 my $method = 'begin_' . ($args{type} || 'class');
66 Module::Load::load($args{extends}) if $args{extends};
67 my $meta = Object::Pad::MOP::Class->$method(
68 $class,
69 (
70 $args{extends}
71 ? (extends => $args{extends})
72 : ()
73 ),
74 );
75 $args{does} = [ $args{does} // () ] unless ref $args{does};
76 for my $role ($args{does}->@*) {
77 Module::Load::load($role) unless eval { Object::Pad::MOP::Class->for_class($role) };
78 $meta->add_role($role);
79 }
80 return $meta;
81 }
82 return $pkg;
83 }
84  
85 1;
86  
87 __END__
↑ Summary Full/Role.pm »