App-PhotoDB
view release on metacpan or search on metacpan
docs/CONTRIBUTING.pod view on Meta::CPAN
the diffs with a meaningful commit message.
=head2 Application conventions
The application frontend, C<photodb>, is the smallest possible script to determine which command
the user wants to run, map the command to a handler using C<commands.pm> and then execute the
handler from C<handlers.pm> to complete the user interaction.
Handlers are pieces of code which carry out user interaction, and encode logic about what information
to collect. They tend to be simple but extensive. Most handlers simply run through a list of prompts to
build a hash of data, which is then inserted/updated/etc into the database backend. Some handlers
contain simple logic to make decisions or loops to simplify bulk operations.
Handlers rely on functions in C<funcs.pm> which are reusable pieces of code which do not interact
with the user, but perform common operations like selecting from a database, validating user input,
etc.
=head2 Contributing your work
Pull requests are welcome.
lib/App/PhotoDB/funcs.pm view on Meta::CPAN
=item * C<$table> Name of table to update
=item * C<$where> Where clause, formatted for SQL::Abstract
=item * C<$silent> Suppress output
=item * C<$log> Write an event to the database log. Defaults to C<1>.
=head4 Returns
The number of rows updated
=cut
sub updaterecord {
# Pass in a hashref of arguments
my $href = shift;
# Unpack the hashref and set default values
my $db = $href->{db}; # DB handle
my $data = $href->{data}; # Hash of new values to update
lib/App/PhotoDB/funcs.pm view on Meta::CPAN
return 0;
}
# Work out affected rows
my $rowcount = &lookupval({db=>$db, col=>'count(*)', table=>$table, where=>$where});
# Dump data for debugging
print "\n\nThis is what I will update into $table where:\n" unless $silent;
print Dump($where) unless $silent;
print Dump($data) unless $silent;
print "\n$rowcount records will be updated\n" unless $silent;
print "\n" unless $silent;
# Build query
my $sql = SQL::Abstract->new;
my($stmt, @bind) = $sql->update($table, $data, $where);
# Final confirmation
unless ($silent) {
if (!&prompt({default=>'yes', prompt=>'Proceed?', type=>'boolean'})) {
print "Aborted!\n";
lib/App/PhotoDB/handlers.pm view on Meta::CPAN
}
}
}
}
my $stillfsonly = $numfsonly - $x;
print "Added $x scans to the database. There are $stillfsonly scans on the filesystem but not in the database.\n";
} else {
print "All scans on the filesystem are already in the database\n";
}
# Re-search filesystem basepath & DB in case it was updated above
@fsfiles = &fsfiles;
@dbfiles = &dbfiles({db=>$db});
# Find scans only in the database
my @dbonly = array_minus(@dbfiles, @fsfiles);
my $numdbonly = scalar @dbonly;
# Scans only in the db
if ($numdbonly>0 && &prompt({prompt=>"Audit $numdbonly scans that exist only in the database and not on the filesystem?", type=>'boolean', default=>'no', required=>1})) {
my $x = 0;
( run in 0.340 second using v1.01-cache-2.11-cpan-05444aca049 )