File Coverage

blib/lib/Full/Class.pm
Criterion Covered Total %
statement 31 32 96.8
branch 5 10 50.0
condition 5 11 45.4
subroutine 5 5 100.0
pod n/a
total 46 58 79.3


line stmt bran cond sub pod time code
1             package Full::Class;
2              
3 4     4   1105804 use Full::Pragmata qw(:v1);
  4         15  
  4         22  
4 4     4   32 use parent qw(Full::Pragmata);
  4         9  
  4         30  
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 to provide method parameter checks.
29             Note that the C keyword is required, see L 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 class, providing the
38             L, L and C keywords.
39              
40             This also makes available a L instance in the C<$log> package variable,
41             and for L support you get C<$tracer> as an L
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 4     4   716 use Object::Pad;
  4         8  
  4         67  
55 4     4   803 use Object::Pad qw(:experimental(mop));
  4         11  
  4         45  
56              
57 14     14   54413 sub import ($called_on, $version, %args) {
  14         27  
  14         25  
  14         24  
  14         23  
58 14         20 my $class = __PACKAGE__;
59 14   33     97 my $pkg = $args{target} // caller(0);
60              
61 14         79 $class->next::method($version, target => $pkg);
62 14 50 33     118 if(my $class = $args{class} // $pkg) {
63 14         103 Object::Pad->import_into($pkg, ":experimental(init_expr mop custom_field_attr)");
64              
65 14   50     2105 my $method = 'begin_' . ($args{type} || 'class');
66 14 50       40 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 14 50       95 : ()
73             ),
74             );
75 14 50 66     1684 $args{does} = [ $args{does} // () ] unless ref $args{does};
76 14         46 for my $role ($args{does}->@*) {
77 1 50       2 Module::Load::load($role) unless eval { Object::Pad::MOP::Class->for_class($role) };
  1         4  
78 1         57 $meta->add_role($role);
79             }
80 14         3635 return $meta;
81             }
82 0           return $pkg;
83             }
84              
85             1;
86              
87             __END__