X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FHelper%2FModel%2FDBIC%2FSchema.pm;h=0a5b49073e0b6de8a57e584b5597512c191f7407;hb=bf4bdab65638c0d4aad4e4d21d5d8e8149dc0329;hp=32a663a8fa3f66fb185cf234c14429bd392c9be0;hpb=fdbe669ec4c1a8f46c43d69576fe5d52a054de51;p=catagits%2FCatalyst-Model-DBIC-Schema.git diff --git a/lib/Catalyst/Helper/Model/DBIC/Schema.pm b/lib/Catalyst/Helper/Model/DBIC/Schema.pm index 32a663a..0a5b490 100644 --- a/lib/Catalyst/Helper/Model/DBIC/Schema.pm +++ b/lib/Catalyst/Helper/Model/DBIC/Schema.pm @@ -4,7 +4,7 @@ use namespace::autoclean; use Moose; no warnings 'uninitialized'; -our $VERSION = '0.43'; +our $VERSION = '0.45'; $VERSION = eval $VERSION; use Carp; @@ -15,6 +15,8 @@ use MooseX::Types::Moose qw/Str HashRef Bool ArrayRef/; use Catalyst::Model::DBIC::Schema::Types 'CreateOption'; use List::MoreUtils 'firstidx'; use Scalar::Util 'looks_like_number'; +use File::Find 'finddepth'; +use Try::Tiny; =head1 NAME @@ -143,6 +145,7 @@ has schema_class => (is => 'ro', isa => Str, required => 1); has loader_args => (is => 'rw', isa => HashRef); has connect_info => (is => 'rw', isa => HashRef); has old_schema => (is => 'rw', isa => Bool, lazy_build => 1); +has is_moose_schema => (is => 'rw', isa => Bool, lazy_build => 1); has components => (is => 'rw', isa => ArrayRef); =head1 METHODS @@ -265,7 +268,8 @@ sub _parse_loader_args { %result = ( relationships => 1, - use_moose => 1, + use_moose => $self->is_moose_schema ? 1 : 0, + col_collision_map => 'column_%s', (!$self->old_schema ? ( use_namespaces => 1 ) : ()), @@ -398,6 +402,37 @@ sub _build_old_schema { 0; } +sub _build_is_moose_schema { + my $self = shift; + + my @schema_parts = split '::', $self->schema_class; + my $schema_dir = + File::Spec->catfile($self->helper->{base}, 'lib', @schema_parts); + + # assume yes for new schemas + return 1 if not -d $schema_dir; + + my $uses_moose = 1; + + try { + finddepth(sub { + return if $File::Find::name !~ /\.pm\z/; + + open my $fh, '<', $File::Find::name + or die "Could not open $File::Find::name: $!"; + + my $code = do { local $/; <$fh> }; + close $fh; + + $uses_moose = 0 if $code !~ /\nuse Moose;\n/; + + die; + }, $schema_dir); + }; + + return $uses_moose; +} + sub _data_struct_to_string { my ($self, $data) = @_;