| 1 | package WWW::Garden::Design::Database::MojoDriver; | ||
| 2 | |||
| 3 | use Moo; | ||
| 4 | |||
| 5 | use feature ':5.10'; | ||
| 6 | use strict; | ||
| 7 | use warnings; | ||
| 8 | |||
| 9 | use Data::Dumper::Concise; # For Dumper(). | ||
| 10 | |||
| 11 | use DBI; | ||
| 12 | |||
| 13 | use Types::Standard qw/Any HashRef Object/; | ||
| 14 | |||
| 15 | use WWW::Garden::Design::Database::Mojo; | ||
| 16 | use WWW::Garden::Design::Util::Config; | ||
| 17 | |||
| 18 | has config => | ||
| 19 | ( | ||
| 20 | default => sub{WWW::Garden::Design::Util::Config -> new -> config}, | ||
| 21 | is => 'rw', | ||
| 22 | isa => HashRef, | ||
| 23 | required => 0, | ||
| 24 | ); | ||
| 25 | |||
| 26 | has db => | ||
| 27 | ( | ||
| 28 | is => 'rw', | ||
| 29 | isa => Object, | ||
| 30 | required => 0, | ||
| 31 | ); | ||
| 32 | |||
| 33 | has dbh => | ||
| 34 | ( | ||
| 35 | is => 'rw', | ||
| 36 | isa => Any, | ||
| 37 | required => 0, | ||
| 38 | ); | ||
| 39 | |||
| 40 | our $VERSION = '0.97'; | ||
| 41 | |||
| 42 | # ----------------------------------------------- | ||
| 43 | |||
| 44 | sub BUILD | ||
| 45 | { | ||
| 46 | my($self) = @_; | ||
| 47 | my($config) = $self -> config; | ||
| 48 | my($attr) = | ||
| 49 | { | ||
| 50 | AutoCommit => $$config{AutoCommit}, | ||
| 51 | mysql_enable_utf8 => $$config{mysql_enable_utf8}, #Ignored if not using MySQL. | ||
| 52 | RaiseError => $$config{RaiseError}, | ||
| 53 | sqlite_unicode => $$config{sqlite_unicode}, #Ignored if not using SQLite. | ||
| 54 | }; | ||
| 55 | |||
| 56 | $self -> dbh(DBI -> connect($$config{dsn}, $$config{username}, $$config{password}, $attr) ); | ||
| 57 | $self -> db(WWW::Garden::Design::Database::Mojo -> new({dbh => $self -> dbh}) ); | ||
| 58 | |||
| 59 | } # End of BUILD; | ||
| 60 | |||
| 61 | # -------------------------------------------------- | ||
| 62 | |||
| 63 | sub arrays | ||
| 64 | { | ||
| 65 | my($self, $sql) = @_; | ||
| 66 | |||
| 67 | return $self -> db -> arrays($sql); | ||
| 68 | |||
| 69 | } # End of arrays. | ||
| 70 | |||
| 71 | # -------------------------------------------------- | ||
| 72 | |||
| 73 | sub hashes | ||
| 74 | { | ||
| 75 | my($self, $sql, $key) = @_; | ||
| 76 | |||
| 77 | return $self -> db -> hashes($sql, $key); | ||
| 78 | |||
| 79 | } # End of hashes. | ||
| 80 | |||
| 81 | # -------------------------------------------------- | ||
| 82 | |||
| 83 | 1; | ||
| 84 | |||
| 85 | =pod | ||
| 86 | |||
| 87 | =head1 NAME | ||
| 88 | |||
| 89 | WWW::Garden::Design::Database::MojoDriver - Manage the 'flowers' database | ||
| 90 | |||
| 91 | =head1 Machine-Readable Change Log | ||
| 92 | |||
| 93 | The file Changes was converted into Changelog.ini by L<Module::Metadata::Changes>. | ||
| 94 | |||
| 95 | =head1 Version Numbers | ||
| 96 | |||
| 97 | Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions. | ||
| 98 | |||
| 99 | =head1 Repository | ||
| 100 | |||
| 101 | L<https://github.com/ronsavage/WWW-Garden-Design> | ||
| 102 | |||
| 103 | =head1 Support | ||
| 104 | |||
| 105 | Email the author, or log a bug on RT: | ||
| 106 | |||
| 107 | L<https://rt.cpan.org/Public/Dist/Display.html?Name=WWW::Garden::Design>. | ||
| 108 | |||
| 109 | =head1 Author | ||
| 110 | |||
| 111 | L<WWW::Garden::Design> was written by Ron Savage I<E<lt>ron@savage.net.auE<gt>> in 2014. | ||
| 112 | |||
| 113 | My homepage: L<https://savage.net.au/>. | ||
| 114 | |||
| 115 | =head1 Copyright | ||
| 116 | |||
| 117 | Australian copyright (c) 2018, Ron Savage. | ||
| 118 | |||
| 119 | All Programs of mine are 'OSI Certified Open Source Software'; | ||
| 120 | you can redistribute them and/or modify them under the terms of | ||
| 121 | The Perl License, a copy of which is available at: | ||
| 122 | http://dev.perl.org/licenses/ | ||
| 123 | |||
| 124 | =cut |