Bigtop
view release on metacpan or search on metacpan
lib/Bigtop/Backend/Model/GantryDBIxClass.pm view on Meta::CPAN
package Bigtop::Backend::Model::GantryDBIxClass;
use strict; use warnings;
use Bigtop::Backend::Model;
use File::Spec;
use Inline;
use Bigtop;
#-----------------------------------------------------------------
# Register keywords in the grammar
#-----------------------------------------------------------------
BEGIN {
Bigtop::Parser->add_valid_keywords(
Bigtop::Keywords->get_docs_for(
'field',
'accessor',
'add_columns',
)
);
}
#-----------------------------------------------------------------
# The Default Template
#-----------------------------------------------------------------
our $template_is_setup = 0;
our $default_template_text = <<'EO_TT_blocks';
[% BLOCK stub_base_model %]
package [% app_name %]::Model;
use strict; use warnings;
use base 'DBIx::Class::Schema';
use [% app_name %]::GENModel;
sub get_db_options {
return { AutoCommit => 1 };
}
1;
=head1 NAME
[% app_name %]::Model - schema class for [% app_name +%]
=head1 SYNOPSIS
In your base module:
use [% app_name %]::Model;
sub schema_base_class { return '[% app_name %]::Model'; }
use Gantry::Plugins::DBIxClassConn qw( get_schema );
[%- FOREACH table_model IN table_models -%]
use [% app_name %]::Model::[% table_model %] qw( $[% table_model | upper %] );
[%- END -%]
=head1 DESCRIPTION
This module was generated by Bigtop. But, feel free to edit it. You
might even want to update these docs.
=over 4
=item get_db_options
The generated version sets AutoCommit to 1, this assumes that you will
do all transaction work via the DBIx::Class API.
=back
=head1 DEPENDENCIES
Gantry::Utils::DBIxClass
[% app_name %]::GENModel
=head1 AUTHOR
[% FOREACH author IN authors %]
[% author.0 %][% IF author.1 %], E<lt>[% author.1 %]E<gt>[% END %]
[% END %]
=head1 COPYRIGHT AND LICENSE
Copyright (C) [% year %] [% copyright_holder %]
[% IF license_text %]
[% ELSE %]
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.6 or,
at your option, any later version of Perl 5 you may have available.
[% END %]
=cut
[% END %]
[% BLOCK gen_base_model %]
package [% app_name %]::Model;
use strict; use warnings;
__PACKAGE__->load_classes( qw/
[% FOREACH table_model IN table_models %]
[% table_model %]
[% END %]
/ );
1;
=head1 NAME
[% app_name %]::GENModel - regenerating schema for [% app_name %]
=head1 SYNOPSIS
In your base schema:
use base 'DBIx::Class::Schema';
use [% app_name %]::GENModel;
=head1 DESCRIPTION
This module was generated by Bigtop (and IS subject to regeneration).
=head1 DEPENDENCIES
Gantry::Utils::DBIxClass
=head1 AUTHOR
[% FOREACH author IN authors %]
[% author.0 %][% IF author.1 %], E<lt>[% author.1 %]E<gt>[% END %]
[% END %]
=head1 COPYRIGHT AND LICENSE
Copyright (C) [% year %] [% copyright_holder %]
[% IF license_text %]
[% ELSE %]
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.6 or,
at your option, any later version of Perl 5 you may have available.
[% END %]
=cut
[% END %]
[% BLOCK stub_table_module %]
package [% package_name %];
use strict; use warnings;
use base '[% base_class || base_class_default %]', 'Exporter';
use [% gen_package_name %];
our $[% package_alias %] = '[% package_name %]';
our @EXPORT_OK = ( '$[% package_alias %]' );
1;
=head1 NAME
[% package_name %] - model for [% table_name %] table (stub part)
=head1 DESCRIPTION
This model inherits from its generated helper, which inherits from
[% base_class || base_class_default %]. It was generated by Bigtop, but is
NOT subject to regeneration.
=head1 METHODS (mixed in from [% gen_package_name %])
You may use all normal [% base_class || base_class_default %] methods and the
ones listed here:
=over 4
=item get_foreign_display_fields
=item get_foreign_tables
=item foreign_display
=item table_name
[% FOREACH option_field IN option_fields %]
=item [% option_field.name %]_display
[% END %]
=back
=cut
[% END %]
[% BLOCK gen_table_module %]
# NEVER EDIT this file. It was generated and will be overwritten without
# notice upon regeneration of this application. You have been warned.
package [% package_name %];
use strict; use warnings;
__PACKAGE__->load_components( qw/ [% load_components %] / );
__PACKAGE__->table( '[% real_table_name %]' );
__PACKAGE__->add_columns( qw/
[% FOREACH column IN regular_accessor_columns %]
[% column +%]
[% END %]
/ );
[% IF special_accessor_columns.size > 0 %]
__PACKAGE__->add_columns(
[% FOREACH column IN special_accessor_columns %]
[% column.name %] => { accessor => '[% column.accessor %]', },
[% END %]
);
[% END %]
[% IF add_columns.size > 0 %]
__PACKAGE__->add_columns(
[% FOREACH column IN add_columns %]
lib/Bigtop/Backend/Model/GantryDBIxClass.pm view on Meta::CPAN
[% END %]
[% FOREACH has_a IN has_a_list %]
__PACKAGE__->belongs_to( [% has_a.column %] => '[% base_package_name %]::[% has_a.table %]' );
[% END %]
__PACKAGE__->base_model( '[% app_name %]::Model' );
[% FOREACH has_many IN has_manys %]
__PACKAGE__->has_many( [% has_many.name %] => '[% app_name %]::Model::[% has_many.table %]'[% IF has_many.field.defined %], '[% has_many.field %]'[% END %] );
[% END %]
[% FOREACH has_many IN three_ways %]
__PACKAGE__->has_many(
[% has_many.join_name %] => '[% has_many.three_way_model %]',
'[% has_many.current_table %]'
);
__PACKAGE__->many_to_many(
[% has_many.foreign_name %] => '[% has_many.join_name %]',
'[% has_many.foreign_key %]'
);
[% END %]
[% IF foreign_display_columns %]sub get_foreign_display_fields {
return [ qw( [% foreign_display_columns %] ) ];
}
[% END %]
sub get_foreign_tables {
return qw(
[% FOREACH foreign_table IN foreign_tables %]
[% base_package_name %]::[% foreign_table +%]
[% END %]
);
}
[% IF foreign_display_columns %]sub foreign_display {
my $self = shift;
[% foreign_display_body %]
}
[% END %]
sub table_name {
return '[% table_name %]';
}
[%- IF option_fields.0 +%]
[% extra_methods = [] %]
my %select_map_for = (
[% FOREACH option_field IN option_fields %]
[% meth_name = option_field.name;
extra_methods.push( "${meth_name}_display" ) %]
[% option_field.name %] => {
[% FOREACH option IN option_field.options %]
[% option.db_value %] => '[% option.label %]',
[% END %]
},
[% END %]
);
[% FOREACH option_field IN option_fields %]
sub [% option_field.name %]_display {
my $self = shift;
my $[% option_field.name %] = defined $self->[% option_field.name %] ? $self->[% option_field.name %] : '';
return $select_map_for{ [% option_field.name %] }{ $[% option_field.name %] }
|| $[% option_field.name %];
}
[% END %]
[% END %]
1;
=head1 NAME
[% gen_package_name %] - model for [% table_name %] table (generated part)
=head1 DESCRIPTION
This model inherits from [% base_class || base_class_default %].
It was generated by Bigtop, and IS subject to regeneration.
=head1 METHODS
You may use all normal [% base_class || base_class_default %] methods and the
ones listed here:
=over 4
=item get_foreign_display_fields
=item get_foreign_tables
=item foreign_display
=item table_name
[% FOREACH extra_method IN extra_methods %]
=item [% extra_method +%]
[% END %]
=back
=cut
[% END %]
[% BLOCK gen_three_way_module %]
package [% stub_package %];
use strict; use warnings;
use base '[% model_base_class %]', 'Exporter';
use [% gen_package %];
our $[% package_alias %] = '[% stub_package %]';
our @EXPORT_OK = ( '$[% package_alias %]' );
1;
=head1 NAME
[% stub_package %] - model for [% table_name %] table (stub part)
=head1 DESCRIPTION
This model inherits from its generated helper, which inherits from
Gantry::Utils::DBIxClass. It was generated by Bigtop, but is
NOT subject to regeneration.
=cut
[% END %]
[% BLOCK gen_three_way_gen_module %]
# NEVER EDIT this file. It was generated and will be overwritten without
# notice upon regeneration of this application. You have been warned.
package [% stub_package %];
use strict; use warnings;
__PACKAGE__->load_components( qw/ PK::Auto Core / );
__PACKAGE__->table( '[% table_name %]' );
__PACKAGE__->add_columns( qw/
id
[% FOREACH other_table IN joined_tables %]
[% other_table +%]
[% END %]
[% FOREACH extra IN extra_fields %]
[% extra +%]
[% END %]
/ );
__PACKAGE__->set_primary_key( 'id' );
__PACKAGE__->base_model( '[% app_name %]::Model' );
[% FOREACH other_table IN joined_tables %]
__PACKAGE__->belongs_to( [% other_table %] => '[% app_name %]::Model::[% other_table %]' );
[% END %]
sub get_foreign_tables {
return qw(
);
}
sub table_name {
return '[% table_name %]';
}
[% IF option_fields.0 +%]
[% extra_methods = [] %]
my %select_map_for = (
[% FOREACH option_field IN option_fields %]
[% option_field.name %] => {
[% FOREACH option IN option_field.options %]
[% option.db_value %] => '[% option.label %]',
[% END %]
},
[% END %]
);
[% FOREACH option_field IN option_fields %]
[% meth_name = option_field.name;
( run in 0.310 second using v1.01-cache-2.11-cpan-5511b514fd6 )