File perl-Mojo-Pg.spec of Package perl-Mojo-Pg

#
# spec file for package perl-Mojo-Pg
#
# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


Name:           perl-Mojo-Pg
Version:        2.35
Release:        0
%define cpan_name Mojo-Pg
Summary:        Mojolicious ♥ PostgreSQL
License:        Artistic-2.0
Group:          Development/Libraries/Perl
Url:            http://search.cpan.org/dist/Mojo-Pg/
Source0:        http://www.cpan.org/authors/id/S/SR/SRI/%{cpan_name}-%{version}.tar.gz
Source1:        cpanspec.yml
BuildArch:      noarch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  perl
BuildRequires:  perl-macros
BuildRequires:  perl(DBD::Pg) >= 3.005001
BuildRequires:  perl(Mojolicious) >= 7.15
Requires:       perl(DBD::Pg) >= 3.005001
Requires:       perl(Mojolicious) >= 7.15
%{perl_requires}

%description
Mojo::Pg is a tiny wrapper around DBD::Pg that makes at
http://www.postgresql.org a lot of fun to use with the at
http://mojolicious.org real-time web framework.

Database and statement handles are cached automatically, and will be reused
transparently to increase performance. You can handle connection timeouts
gracefully by holding on to them only for short amounts of time.

  use Mojolicious::Lite;
  use Mojo::Pg;

  helper pg => sub { state $pg = Mojo::Pg->new('postgresql://postgres@/test') };

  get '/' => sub {
    my $c  = shift;
    my $db = $c->pg->db;
    $c->render(json => $db->query('select now() as now')->hash);
  };

  app->start;

In this example application, we create a 'pg' helper to store a Mojo::Pg
object. Our action calls that helper and uses the method Mojo::Pg/"db" to
dequeue a Mojo::Pg::Database object from the connection pool. Then we use
the method Mojo::Pg::Database/"query" to execute an at
http://www.postgresql.org/docs/current/static/sql.html statement, which
returns a Mojo::Pg::Results object. And finally we call the method
Mojo::Pg::Results/"hash" to retrieve the first row as a hash reference.

While all I/O operations are performed blocking, you can wait for long
running queries asynchronously, allowing the Mojo::IOLoop event loop to
perform other tasks in the meantime. Since database connections usually
have a very low latency, this often results in very good performance.

Every database connection can only handle one active query at a time, this
includes asynchronous ones. To perform multiple queries concurrently, you
have to use multiple connections.

  # Performed concurrently (5 seconds)
  $pg->db->query('select pg_sleep(5)' => sub {...});
  $pg->db->query('select pg_sleep(5)' => sub {...});

All cached database handles will be reset automatically if a new process
has been forked, this allows multiple processes to share the same Mojo::Pg
object safely.

%prep
%setup -q -n %{cpan_name}-%{version}
find . -type f ! -name \*.pl -print0 | xargs -0 chmod 644

%build
%{__perl} Makefile.PL INSTALLDIRS=vendor
%{__make} %{?_smp_mflags}

%check
%{__make} test

%install
%perl_make_install
%perl_process_packlist
%perl_gen_filelist

%files -f %{name}.files
%defattr(-,root,root,755)
%doc Changes examples LICENSE README.md

%changelog
openSUSE Build Service is sponsored by