Helper/Schema/GenerateSource.pm

filter: Statementstmt 100% 24 / 24 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 94.7% 36 / 38 CC 3 SCAR 3.3
CC
3
Cov
93%
_schema_class
2.1
_generate_class
2.0
BEGIN
1.0
CRAP 1.4
« Helper/ResultSet/Me.pm ↑ Summary Helper/Row/StorageValues.pm »
1 package DBIx::Class::Helper::Schema::GenerateSource;
2 1 $DBIx::Class::Helper::Schema::GenerateSource::VERSION = '2.033001';
3 # ABSTRACT: Generate sources directly from your Schema
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use parent 'DBIx::Class::Schema';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶sub _schema_class { blessed($_[0]) || $_[0] }
Subroutine _schema_class: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) or $_[0] 1 0 1
13  
14 sub _generate_class_name {
15 1 ▶ $_[0]->_schema_class . '::GeneratedResult::__' . uc $_[1]
Subroutine _generate_class_name: called CC=1 SCAR=0.0
16 }
17  
18 sub _generate_class {
19 1 ▶ die $@ unless eval "
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _generate_class: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
unless eval "\n package $_[1]; use parent '$_[2]'; __PACKAGE__->table(__PACKAGE__->table); 1;\n " 0 1 1
20 package $_[1]; use parent '$_[2]'; __PACKAGE__->table(__PACKAGE__->table); 1;
21 ";
22 }
23  
24 sub generate_source {
25 1 ▶ my ($self, $moniker, $base) = @_;
Subroutine generate_source: called CC=1 SCAR=0.0
Pod documented
26  
27 1 my $class = $self->_generate_class_name($moniker);
28 1 $self->_generate_class($class, $base);
29 1 $self->register_class($moniker, $class);
30 }
31  
32 1 1;
33  
34 __END__
35  
36 =pod
37  
38 =head1 NAME
39  
40 DBIx::Class::Helper::Schema::GenerateSource - Generate sources directly from your Schema
41  
42 =head1 SYNOPSIS
43  
44 package MyApp::Schema;
45  
46 __PACKAGE__->load_components('Helper::Schema::GenerateSource');
47  
48 __PACKAGE__->generate_source(User => 'MyCompany::BaseResult::User');
49  
50 =head1 DESCRIPTION
51  
52 This helper allows you to handily and correctly add new result sources to your
53 schema based on existing result sources. Typically this would be done with
54 something like:
55  
56 package MyApp::Schema::Result::MessegeQueue;
57  
58 use parent 'MyCo::Schema::Result::MessageQueue';
59  
60 __PACKAGE__->table(__PACKAGE__->table);
61  
62 1;
63  
64 which clearly is in its own file. This should still be done when you need to
65 add columns or really do B<anything> other than just basic addition of the
66 result source to your schema.
67  
68 B<Note>: This component correctly generates an "anonymous" subclass of the given
69 base class. Do not depend on the name of the subclass as it is currently
70 considered unstable.
71  
72 =head1 METHODS
73  
74 =head2 generate_source
75  
76 $schema->generate_source(User => 'MyCompany::BaseResult::User')
77  
78 The first argument to C<generate_source> is the C<moniker> to register the
79 class as, the second argument is the base class for the new result source.
80  
81 =head1 AUTHOR
82  
83 Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
84  
85 =head1 COPYRIGHT AND LICENSE
86  
87 This software is copyright (c) 2016 by Arthur Axel "fREW" Schmidt.
88  
89 This is free software; you can redistribute it and/or modify it under
90 the same terms as the Perl 5 programming language system itself.
91  
92 =cut
« Helper/ResultSet/Me.pm ↑ Summary Helper/Row/StorageValues.pm »