ASP4

 view release on metacpan or  search on metacpan

sbin/asphelper  view on Meta::CPAN

CODE
  close($ofh);
}# end unless()

# Only write the base Model class if we have Class::DBI::Lite
my $CDBIL_Version = 0;
eval {
  require Class::DBI::Lite;
  $CDBIL_Version = $Class::DBI::Lite::VERSION = $Class::DBI::Lite::VERSION;
};
if( $dbName && $Class::DBI::Lite::VERSION )
{
  unless( -f "common/lib/$appFolder/db/model.pm" )
  {
    warn "common/lib/$appFolder/db/model.pm\n";
    open my $ofh, '>', "common/lib/$appFolder/db/model.pm"
      or die "Cannot open 'common/lib/$appFolder/db/model.pm' for writing: $!";
    print $ofh <<"CODE";

@{[ 'package' ]} @{['']} $appFolder\::db::model;

use strict;
use warnings 'all';
use base 'Class::DBI::Lite::mysql';
use ASP4::ConfigLoader;

my \$Config = ASP4::ConfigLoader->load();
my \$conn = \$Config->data_connections->main;
__PACKAGE__->connection(
  \$conn->dsn,
  \$conn->username,
  \$conn->password
);

1;# return true:

\=pod

\=head1 NAME

$appName\::db::model - Base class for all $appName entity classes.

\=head1 SYNOPSIS

  # In your class:
  
  package $appName\::db::thing;
  
  use strict;
  use warnings 'all';
  use base '$appName\::db::model';
  
  __PACKAGE__->set_up_table('things');
  
  1;# return true:

\=head1 DESCRIPTION

This module was generated by $0 on @{[ scalar(localtime()) ]}.

B<***IT IS SAFE to make changes to this file, as it will not be overwritten.***>.

\=head1 SEE ALSO

L<Class::DBI::Lite>

\=cut

CODE
    close($ofh);
  }# end unless()
}# end if()


unless( -f "www/t/010-basic/010-compile.t" )
{
  warn "www/t/010-basic/010-compile.t\n";
  open my $ofh, '>', "www/t/010-basic/010-compile.t"
    or die "Cannot open 'www/t/010-basic/010-compile.t' for writing: $!";
  print $ofh <<"TEST";
#!/usr/bin/perl -w

use strict;
use warnings 'all';
use Test::More 'no_plan';
use ASP4::API;
my \$api = ASP4::API->new;

TEST

  if( $CDBIL_Version )
  {
print $ofh <<"MORE";
@{[ $dbName ? qq(use_ok('$appName\::db::model');) : '' ]}
MORE
  }# end if()
  
  print $ofh <<"TEST";

my \$res = \$api->ua->post("/handlers/$hClass.www.echo", {
  hello => "world"
});
like \$res->content, qr('hello'\\s+\\=\>\\s+'world'), "/handlers/$hClass.www.echo?hello=world works";

ok( \$res = \$api->ua->get("/"), "Got '/'.");
ok( \$res->is_success, "GET / is successful.");
ok( \$res->content, "Got some content also.");


TEST

  if( $dbName && $dbUser )
  {
    print $ofh <<"TEST";
for( 0..10 )
{
  like \$res->content, qr(visited this page \$_ time), "Simple session counter: \$_ visits recorded.";
  \$res = \$api->ua->get("/");
}# end for()

TEST



( run in 0.722 second using v1.01-cache-2.11-cpan-39bf76dae61 )