AuditAny/Util/ResultMaker.pm

filter: Statementstmt 97.4% 38 / 39 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 100% 1 / 1 totaltotal 91.0% 51 / 56 CC 5 SCAR 9.9
CC
5
Cov
91%
initialize
5.1
__ANON__
1.1
BEGIN
1.0
CRAP 2.7
« AuditAny/Collector/AutoDBIC.pm ↑ Summary AuditAny/Util/SchemaMaker.pm »
1 package DBIx::Class::AuditAny::Util::ResultMaker;
2 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: On-the-fly creation of DBIC Result classes
6  
7 =head1 NAME
8  
9 DBIx::Class::AuditAny::Util::ResultMaker - On-the-fly creation of DBIC Result classes
10  
11 =head1 DESCRIPTION
12  
13 This package provides an easy way to conjurer new DBIC result classes into existence. It
14 is typically used by L<DBIx::Class::AuditAny::Util::SchemaMaker> and not called directly.
15  
16 =head1 ATTRIBUTES
17  
18 =cut
19  
20 11 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 11 ▶use MooX::Types::MooseLike::Base qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 11 require Class::MOP::Class;
24 11 ▶use DBIx::Class::AuditAny::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26  
27 =head2 class_name
28  
29 Required. Full class name of the result class to be created
30  
31 =cut
32 11 has 'class_name', is => 'ro', isa => Str, required => 1;
33  
34 =head2 class_opts
35  
36 Optional extra params to supply to C<< Class::MOP::Class->create >>
37  
38 =cut
39 44 ▶has 'class_opts', is => 'ro', isa => HashRef, default => sub {{}};
Subroutine __ANON__: called CC=1 SCAR=0.0
40  
41 =head2 table_name
42  
43 Required. The name of the table as would be supplied to C<< ->table() >> in the
44 result class.
45  
46 =cut
47 11 has 'table_name', is => 'ro', isa => Str, required => 1;
48  
49 =head2 columns
50  
51 Required. ArrayRef of DBIC column definitions suitable as arguments for C<< ->add_columns() >>
52  
53 =cut
54 11 has 'columns', is => 'ro', isa => ArrayRef, required => 1;
55  
56 =head2 call_class_methods
57  
58 Optional ArrayRef consumed in pairs, with the first value used as a method name, and the
59 second value an ArrayRef holding the args to supply to the method. Each of these are called
60 as class methods on the result class. This allows for any other calls to be handled, such as
61 adding uniq keys, and so on.
62  
63 =cut
64 0 ▶has 'call_class_methods', is => 'ro', isa => ArrayRef, default => sub {[]};
Subroutine __ANON__: not called CC=1 SCAR=1.2
65  
66  
67 =head1 METHODS
68  
69 =head2 initialize
70  
71 Initialization constructor. Expects the above attrs as a HashRef as they would be passed to
72 C<new()>. Creates the specified result class and invokes all the setup methods as defined above.
73  
74 =cut
75 44 ▶sub initialize {
Subroutine initialize: called CC=5 SCAR=16.2
Pod documented
76 44 my $self = shift;
77 44 ▶ $self = $self->new(@_) unless (ref $self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 44 0 44
78
79 44 my $class = $self->class_name;
80 44 ▶ die "class/namespace '$class' already defined!" if (package_exists $class);
Branch: 1 branch
BranchTrueFalseTotal
if &package_exists($class) 0 44 44
81
82 Class::MOP::Class->create($class,
83 superclasses => [ 'DBIx::Class::Core' ],
84 44 ▶ %{ $self->class_opts }
Branch: 1 branch
BranchTrueFalseTotal
"Class::MOP::Class"->create($class, "superclasses", ["DBIx::Class::Core"], %{$self->class_opts;}) or die $@ 44 0 44
85 ) or die $@;
86
87 44 $class->table( $self->table_name );
88
89 44 $class->add_columns( @{$self->columns} );
90
91 44 my @call_list = @{$self->call_class_methods};
92 44 ▶ while (my $meth = shift @call_list) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $meth = shift @call_list) 99 44 143
93 99 my $args = shift @call_list;
94 99 $class->$meth(@$args);
95 }
96  
97 44 return $class;
98 }
99  
100 11 1;
101  
102 __END__
« AuditAny/Collector/AutoDBIC.pm ↑ Summary AuditAny/Util/SchemaMaker.pm »