App-Zapzi

 view release on metacpan or  search on metacpan

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


    # Fallthrough if no valid commands given
    $self->help if $self->run == -1;
}


sub init
{
    my $self = shift;
    my $dir = $self->zapzi_dir;

    $self->run(1);

    if (! $dir || $dir eq '')
    {
        print "Zapzi directory not supplied\n";
    }
    elsif (-d $dir && ! $self->force)
    {
        print "Zapzi directory $dir already exists\n";
        print "To force recreation, run with the --force option\n";
    }
    else
    {
        $self->database->init;
        print "Created Zapzi directory $dir\n\n";
        if ($self->init_config())
        {
            print "\nInitialisation completed. Type 'zapzi help' to view " .
                "command line options\n";
            $self->run(0);
        }
    }
}


sub init_config
{
    my $self = shift;

    if ($self->interactive)
    {
        print "Select configuration options. " .
              "Press enter to accept defaults.\n\n";
    }
    else
    {
        print "Not running interactively, so will use defaults for " .
              "configuration variables.\n";
        print "Use the 'zapzi config' command to view/set these later\n";
    }

    my @keys = App::Zapzi::UserConfig::get_user_init_configurable_keys();
    while (@keys)
    {
        my $key = shift @keys;
        my $value = App::Zapzi::UserConfig::get_default($key);

        if ($self->interactive)
        {
            $value = prompt('s', # validate by sub
                            App::Zapzi::UserConfig::get_description($key),
                            App::Zapzi::UserConfig::get_options($key),
                            $value, # the default value
                            App::Zapzi::UserConfig::get_validater($key));
        }

        # Only ask distribution_destination if distribution_method is set
        if ($key eq 'distribution_method' && lc($value) ne 'nothing')
        {
            unshift @keys, 'distribution_destination';
        }

        return unless App::Zapzi::UserConfig::set($key, $value);
    }

    return 1;
}



sub config
{
    my $self = shift;
    my @args = @_;
    my $command = shift @args;

    $self->run(0);
    if (! $command || $command eq 'get')
    {
        # Get all unless keys were specified
        @args = App::Zapzi::UserConfig::get_user_configurable_keys()
            unless @args;

        for (@args)
        {
            my $key = $_;
            my $doc = App::Zapzi::UserConfig::get_doc($key);
            if ($doc)
            {
                print $doc;
                my $value = App::Zapzi::UserConfig::get($key);
                printf("%s = %s\n\n", $key, $value ? $value : '<not set>');
            }
            else
            {
                print "Config variable '$key' does not exist\n";
                $self->run(1);
            }
        }
    }
    elsif ($command eq 'set')
    {
        if (scalar(@args) != 2)
        {
            print "Invalid config set command - try 'set key value'\n";
            $self->run(1);
        }
        else
        {
            # set key value

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

=head2 run

The current state of the application, -1 means nothing has been done,
0 OK, otherwise an error code. Used for exit code when the process
terminates.

=head2 force

Option to force processing of the init command. Default is unset.

=head2 noarchive

Option to not archive articles on publication

=head2 long

Option to present a detailed listing

=head2 folder

Folder to work on. Default is 'Inbox'

=head2 transformer

Transformer to extract text from the article. Default is '', which
means Zapzi will automatically the best option based on the content
type of the text.

=head2 format

Format to publish a collection of folder articles in.

=head2 encoding

Encoding to publish a collection of folder articles in. Zapzi will
select the best encoding for the content and publication format if not
specified.

=head2 distribute

Method to distribute a published eBook - eg copy, script, email.

=head2 zapzi_dir

The folder where Zapzi files are stored.

=head2 zapzi_ebook_dir

The folder where Zapzi published eBook files are stored.

=head2 database

The instance of App:Zapzi::Database used by the application.

=head2 test_database

If set, use an in-memory database. Used to speed up testing only.

=head2 interactive

If set, this is an interactive session where Zapzi can prompt the user
for input.

=head1 METHODS

=head2 get_app
=method BUILD

At construction time, a copy of the application object is stored and
can be retrieved later via C<get_app>.

=head2 process_args(@args)

Read the arguments C<@args> (normally you'd pass in C<@ARGV> and
process them according to the command line specification for the
application.

=head2 init

Creates the database. Will only do so if the database does not exist
already or if the L<force> attribute is set.

=head2 init_config

On initialiseation, ask the user for settings for configuration
variables. Will not ask if this is being run non-interactively.

=head2 config(@args)

Get or set configuration variables.

If args is 'get' will list out all variables and their values. If args
is 'get x' will list the value of variable x. If args is 'set x y'
will set the value of x to be y.

=head2 validate_folder

Determines if the folder specified exists.

=head2 validate_article_ids(@args)

Determines if @args could be article IDs.

=head2 list

Lists out the articles in L<folder>.

=head2 list_folders

List folder names and article counts.

=head2 make_folder

Create one or more new folders. Will ignore any folders that already
exist.

=head2 delete_folder

Remove one or more new folders. Will not allow removal of system
folders ie Inbox and Archive, but will ignore removal of folders that
do not exist.



( run in 1.046 second using v1.01-cache-2.11-cpan-0b5f733616e )