Catalyst::Helper::Model::EmailStore - Helper for EmailStore Models


Catalyst-Model-EmailStore documentation Contained in the Catalyst-Model-EmailStore distribution.

Index


Code Index:

NAME

Top

Catalyst::Helper::Model::EmailStore - Helper for EmailStore Models

SYNOPSIS

Top

    script/create.pl model EmailStore EmailStore dsn user password

DESCRIPTION

Top

Helper for EmailStore Model.

METHODS

mk_compclass

Reads the Email::Store plugin setup and makes a main model class as well as placeholders for each plugin that was found.

mk_comptest

Makes tests for the EmailStore Model.

SEE ALSO

Top

Catalyst::Manual, Catalyst::Test, Catalyst::Request, Catalyst::Response, Catalyst::Helper

AUTHOR

Top

Sebastian Riedel, sri@oook.de

LICENSE

Top

This library is free software . You can redistribute it and/or modify it under the same terms as perl itself.

NAME

Top

[% class %] - EmailStore Model Component

SYNOPSIS

Top

See [% app %]

DESCRIPTION

Top

EmailStore Model Component.

AUTHOR

Top

[% author %]

LICENSE

Top

This library is free software . You can redistribute it and/or modify it under the same terms as perl itself.

NAME

Top

[% tableclass %] - EmailStore Table Class

SYNOPSIS

Top

See [% app %]

DESCRIPTION

Top

EmailStore Table Class.

AUTHOR

Top

[% author %]

LICENSE

Top

This library is free software . You can redistribute it and/or modify it under the same terms as perl itself.


Catalyst-Model-EmailStore documentation Contained in the Catalyst-Model-EmailStore distribution.
package Catalyst::Helper::Model::EmailStore;

use warnings;
use strict;
use File::Spec;

sub mk_compclass {
  my ( $self, $helper, $dsn, $user, $pass ) = @_;
  $helper->{dsn}  = $dsn  || '';
  $helper->{user} = $user || '';
  $helper->{pass} = $pass || '';
  my $file = $helper->{file};
  $helper->{classes} = [];
  $helper->render_file( 'cdbiclass', $file );
  # push( @{ $helper->{classes} }, $helper->{class} );
  return 1 unless $dsn;

  require Module::Pluggable::Ordered;
  Module::Pluggable::Ordered->import
		( inner => 1, search_path => [ "Email::Store" ] );

  require Email::Store;

  my $path = $file;
  $path =~ s/\.pm$//;
  $helper->mk_dir($path);


  my $prefix = $helper->{app} . '::Model::EmailStore';
  for my $c ( $self->plugins ) {

	 next if $c eq 'Email::Store::DBI';
	 next unless UNIVERSAL::isa( $c, qw/Class::DBI/ );

	 my $model = $c;
	 $model =~ s/^Email::Store/$prefix/;
	 $helper->{tableclass} = $model;

    if ( $model =~ /${prefix}::(.*)$/ ) {
		my @subpath = split( '::', $1 );
		my $f = pop @subpath;
		$helper->mk_dir( File::Spec->catdir( $path, @subpath ) ) if @subpath;
		my $p = File::Spec->catfile( $path, @subpath, "$f.pm" );
		$helper->render_file( 'tableclass', $p );
		push( @{ $helper->{classes} }, $model );
	 }
  }
  return 1;
}

sub mk_comptest {
  my ( $self, $helper ) = @_;
  my $test = $helper->{test};
  my $name = $helper->{name};
  for my $c ( @{ $helper->{classes} } ) {
	 $helper->{tableclass} = $c;
	 my @comps = ( $helper->{tableclass} =~ /\:\:(\w+)\:\:(\w+)$/ );
    shift @comps if $comps[0] =~ /^M(?:odel)?$/;
    shift @comps if $comps[0] eq $name;
	 my $prefix = join( '::', $name, @comps );
	 $prefix =~ s/::/-/g;
	 $helper->render_file( 'test', $helper->next_test($prefix) );
  }
}

1;
__DATA__

__cdbiclass__
package [% class %];

use strict;
use base 'Catalyst::Model::EmailStore';

__PACKAGE__->config(
  dsn                   => '[% dsn %]',
  user                  => '[% user %]',
  password              => '[% pass %]',
  options               => {},
  cdbi_plugins          => [],
  upgrade_relationships => 0
);

1;
__tableclass__
package [% tableclass %];

use strict;

1;
__test__
  use Test::More tests => 2;
use_ok( Catalyst::Test, '[% app %]' );
use_ok('[% tableclass %]');