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 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 9 ▶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 9 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 9 ▶use MooX::Types::MooseLike::Base qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 9 require Class::MOP::Class;
24 9 ▶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 9 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 36 ▶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 9 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 9 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 sub initialize {
76 36 ▶ my $self = shift;
Subroutine initialize: called CC=5 SCAR=16.2
Pod documented
77 36 ▶ $self = $self->new(@_) unless (ref $self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 36 0 36
78
79 36 my $class = $self->class_name;
80 36 ▶ die "class/namespace '$class' already defined!" if (package_exists $class);
Branch: 1 branch
BranchTrueFalseTotal
if &package_exists($class) 0 36 36
81
82 Class::MOP::Class->create($class,
83 superclasses => [ 'DBIx::Class::Core' ],
84 36 ▶ %{ $self->class_opts }
Branch: 1 branch
BranchTrueFalseTotal
"Class::MOP::Class"->create($class, "superclasses", ["DBIx::Class::Core"], %{$self->class_opts;}) or die $@ 0 36 36
85 ) or die $@;
86
87 36 $class->table( $self->table_name );
88
89 36 $class->add_columns( @{$self->columns} );
90
91 36 my @call_list = @{$self->call_class_methods};
92 36 ▶ while (my $meth = shift @call_list) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $meth = shift @call_list) 81 36 117
93 81 my $args = shift @call_list;
94 81 $class->$meth(@$args);
95 }
96  
97 36 return $class;
98 }
99  
100 9 1;
101  
102 __END__
103  
104 =head1 SEE ALSO
105  
106 =over
107  
108 =item *
109  
110 L<DBIx::Class::AuditAny::Util::SchemaMaker>
111  
112 =item *
113  
114 L<DBIx::Class::AuditAny>
115  
116 =item *
117  
118 L<DBIx::Class>
119  
120 =back
121  
122 =head1 SUPPORT
123
124 IRC:
125
126 Join #rapidapp on irc.perl.org.
127  
128 =head1 AUTHOR
129  
130 Henry Van Styn <vanstyn@cpan.org>
131  
132 =head1 COPYRIGHT AND LICENSE
133  
134 This software is copyright (c) 2012-2015 by IntelliTree Solutions llc.
135  
136 This is free software; you can redistribute it and/or modify it under
137 the same terms as the Perl 5 programming language system itself.
138  
139 =cut
« AuditAny/Collector/AutoDBIC.pm ↑ Summary AuditAny/Util/SchemaMaker.pm »