App-PhotoDB

 view release on metacpan or  search on metacpan

lib/App/PhotoDB.pm  view on Meta::CPAN

2. Install it with C<cpanm>:

    cpanm /path/tp/App-PhotoDB-0.00.tar.gz

=head3 Docker

Run PhotoDB on any platform, with Docker

1. Fetch the Docker image

    docker pull djjudas21/photodb

2. Run the image

    docker run -it --rm -v ~/.photodb:/root/.photodb --name photodb photodb

=head2 Configure database connection

There are three methods for connecting to the database:
1. Database and application on same computer
2. Database and application on different computers, connect via native MySQL
3. Database and application on different computers, connect via SSH tunnel

The app and accessory scripts need to know how to connect to the database. The first time you run PhotoDB, you will be prompted to enter connection details for
the database backend. If you need to edit the config in future, the config file is created at C</etc/photodb.ini>.

=head3 Tunnelling

If the database is on a remote server and does not have the MySQL port (3306) open to receive connections, you will need to set up a tunnel. Run the command
below, substituting in the correct hostname and username for the database server.

    ssh -L 3306:localhost:3306 -N <username>@<database.example.com>

Once the tunnel is established, you should be able to connect to the database on C<127.0.0.1:3306> and your connection will be tunnelled. Configure PhotoDB in
the same way as if the database was local. You will need to re-establish the tunnel each time you wish to use PhotoDB.

=head1 BUGS/CAVEATS/etc

Report bugs in the L<Github issue tracker|https://github.com/djjudas21/photodb/issues>

=head1 AUTHOR

Jonathan Gazeley

=head1 SEE ALSO

=over

=item * L<Developing PhotoDB|docs/CONTRIBUTING.pod>

=item * L<Schema description|docs/SCHEMA.pod>

=back

=head1 COPYRIGHT and LICENSE

=cut

use strict;
use warnings;
binmode(STDOUT, ":encoding(UTF-8)");
binmode(STDIN, ":encoding(utf8)");

use App::PhotoDB::funcs qw(/./);
use App::PhotoDB::handlers;
use App::PhotoDB::commands;

# Authoritative distro version
our $VERSION = '0.07';

sub main {
	my $args = shift;

	# Define handlers for each command
	my %handlers = %App::PhotoDB::commands::handlers;

	&welcome;

	# Connect to the database
	my $db = &db({args=>$args});

	# Set up terminal
	our $term = &term;

	# Enter interactive prompt and loop until exited by user
	while (1) {
		my $rv = &prompt({prompt=>'photodb', type=>'text', showtype=>0, showdefault=>0, char=>'>'});
		# Trap important keywords first
		if ($rv eq 'exit' || $rv eq 'quit') {
			last;
		} elsif ($rv =~ /^(\w+) ?([\w-]+)?$/) {
			# Match a command and an optional subcommand
			# Check if the command is defined in the handlers
			my $command = $1;
			if (!exists $handlers{$command}) {
				&nocommand(\%handlers);
				next;
			}

			# Check if the subcommand is defined in the handlers
			my $subcommand = $2;
			if (!exists $handlers{$command}{$subcommand}) {
				&nosubcommand(\%{$handlers{$command}}, $command);
				next;
			}

			# Execute chosen handler
			print "$handlers{$command}{$subcommand}{'desc'}\n";
			$handlers{$command}{$subcommand}{'handler'}->({db=>$db});
		} else {
			# Print list of commands if unknown input is entered
			if ($rv ne '') {
				&nocommand(\%handlers);
			}
		}
	}
	$db->disconnect;
	return;
}

# This ensures the lib loads smoothly
1;



( run in 0.541 second using v1.01-cache-2.11-cpan-140bd7fdf52 )