File Coverage

blib/lib/Dancer2/Plugin/DBIx/Class/ExportBuilder.pm
Criterion Covered Total %
statement 39 40 97.5
branch 5 8 62.5
condition n/a
subroutine 11 11 100.0
pod 0 1 0.0
total 55 60 91.6


line stmt bran cond sub pod time code
1             use Modern::Perl;
2 5     5   33 our $AUTHORITY = 'cpan:GEEKRUTH'; # AUTHORITY
  5         10  
  5         30  
3             use Carp;
4 5     5   646 use Class::C3::Componentised;
  5         12  
  5         257  
5 5     5   28 use curry 2.000001;
  5         8  
  5         127  
6 5     5   2785 use Moo;
  5         1488  
  5         121  
7 5     5   27  
  5         10  
  5         33  
8             has schema_class => (is => 'ro', required => 1);
9              
10             has dsn => (is => 'ro', required => 1);
11              
12             has user => (is => 'ro');
13              
14             has password => (is => 'ro');
15              
16             has schema => (
17             is => 'lazy',
18             builder => sub {
19             my ($self) = @_;
20 10     10   80 $self->_ensure_schema_class_loaded->connect( $self->dsn, $self->user, $self->password );
21 10         30 },
22             );
23              
24             has export_prefix => (is => 'ro');
25              
26             my ( $self, $method ) = @_;
27             return $method unless $self->export_prefix;
28 36     36   54 return join( '_', $self->export_prefix, $method );
29 36 50       91 }
30 0         0  
31             my ($self) = @_;
32             my $class = $self->_ensure_schema_class_loaded;
33             return () unless $class->can('resultset_name_methods');
34 10     10   25 sort keys %{ $class->resultset_name_methods };
35 10         31 }
36 10 100       129  
37 6         13 croak 'No schema class defined' if !$_[0]->schema_class;
  6         115  
38             eval { Class::C3::Componentised->ensure_class_loaded( $_[0]->schema_class ); 1; }
39             or croak 'Schema class ' . $_[0]->schema_class . ' unable to load';
40             return $_[0]->schema_class;
41 20 50   20   70 }
42 20 50       41  
  20         92  
  20         1473397  
43             my ($self) = @_;
44 20         180 my $schema = $self->schema;
45             my %kw;
46             ## no critic qw(Variables::ProhibitPackageVars)
47             $kw{$_} = $schema->$curry::curry($_) for $self->_rs_name_methods;
48 10     10 0 27 return map {
49 10         159 $self->_maybe_prefix_method($_)
50 10         253658 => do {
51             my $code = $kw{$_};
52 10         37 sub { shift; &$code }
53             }
54 10         444 } sort keys %kw;
55 36         77 }
56 36         54  
57 11     11   622886 1;
  11         48  
58 36         133  
59              
60             =pod
61              
62             =encoding UTF-8
63              
64             =head1 NAME
65              
66             Dancer2::Plugin::DBIx::Class::ExportBuilder
67              
68             =head1 VERSION
69              
70             version 1.1000
71              
72             =head1 AUTHOR
73              
74             D Ruth Holloway <ruth@hiruthie.me>
75              
76             =head1 COPYRIGHT AND LICENSE
77              
78             This software is copyright (c) 2022, 2021 by D Ruth Holloway.
79              
80             This is free software; you can redistribute it and/or modify it under
81             the same terms as the Perl 5 programming language system itself.
82              
83             =cut