Palm-Progect

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

    - priorities now working

    - COMPATIBILITY CHANGE: --date-format now split into:
         --date-format      (for Text converter only)
         --csv-date-format  (for CSV converter only)

    - countless API changes to Palm::Progect

    - new guide to the internals (hacking.txt)

    - now generates sensible prefs defaults

[1.9.x] 2002/04/xx
    - unreleased testing versions, leading up to 2.0.0 release
    - Thanks to Mark Allman for testing and feedback

[1.0.2] 2001/09/29
    - progconv couldn't handle paths with dots in them (thanks to Kris Gale
      for the bugreport and patch)
    - don't ignore lines that start with # when they are within
      a multi-line field (i.e. a note)

bin/progconv  view on Meta::CPAN

    my $source_format_name = $converters{$source_format}{'Name'};

    # merge the options for this format into the options
    # we pass to the converter module

    my %Passed_Options = %General_Options;
    for (keys %{$Options{'converters'}{$source_format}}) {
        $Passed_Options{$_} = $Options{'converters'}{$source_format}{$_};
    }

    $progect_db->import_prefs(
        file    => $source,
        format  => $source_format_name,
        %Passed_Options,
    );
    $progect_db->import_records(
        file    => $source,
        format  => $source_format_name,
        %Passed_Options,
    );
}

bin/progconv  view on Meta::CPAN

    my $target_format_name = $converters{$target_format}{'Name'};

    # # merge the options for this format into the options
    # we pass to the converter module

    my %Passed_Options = %General_Options;
    for (keys %{$Options{'converters'}{$target_format}}) {
        $Passed_Options{$_} = $Options{'converters'}{$target_format}{$_};
    }

    $progect_db->export_prefs(
        file    => $target,
        format  => $target_format_name,
        %Passed_Options,
    );
    $progect_db->export_records(
        file    => $target,
        format  => $target_format_name,
        %Passed_Options,
    );
}

hacking.txt  view on Meta::CPAN



Modules
=======
- Palm::Progect                      # Main Progect user-visible API
                                     # - brokers between the Palm::Progect::Record
                                     #   and Palm::Progect::Prefs objects and
                                     #   the Palm::PDB object
                                     #   provides load_db/save_db for Progect pdb files
                                     #   provides import_records/export_records
                                     #   and import_prefs/export_prefs for other formats


- Palm::Progect::Record              # Generic Record, category magic, category class methods
- Palm::Progect::Prefs               # Generic Prefs

- Palm::Progect::VersionDelegator    # Module that actually delegates to version-specific
                                     # DB modules

- Palm::Progect::DB_18::Record.pm    # Database v0.18 specific Record
- Palm::Progect::DB_18::Prefs.pm     # Database v0.18 specific Prefs

hacking.txt  view on Meta::CPAN

- Palm::Progect::Converter::CSV      # Converter for CSV format
- Palm::Progect::Converter::HTML     # Converter for HTML format (tbd)

- Palm::Progect::Constants           # various constants and types
- Palm::Progect::Date                # date string parsing and formatting

Palm::Progect
   | $palm_pdb   (Palm::Raw object - access to raw PDB data)
   | $version    (Current preferred version to use when loading/saving Progect databases)
   | @records    (list of record objects)
   | $prefs      (single prefs object)

   - new

   - load_db (file => $file)

   - save_db (file => $file, version => $version)

   - import_records (type => $type, text => $text, file => $file, %other_args)
        - some drivers will not support record import (e.g. HTML)

        - $converter = Palm::Progect::Converter( type => $type, %other_args );

        - @records = $converter->load_records(text => $text, file => $file );

   - import_prefs
        - some drivers will not support prefs import (e.g. HTML)

        - $converter = Palm::Progect::Converter( type => $type )

        - $prefs     = $converter->load_prefs(text => $text, file => $file );

   - export_records ($type, $text)
        - $converter = Palm::Progect::Converter( type => $type )

        - $text = $converter->save_records(text => $text, file => $file );

   - export_prefs
        - $converter = Palm::Progect::Converter( type => $type )

        - $prefs     = $converter->load_prefs(text => $text, file => $file );

Palm::Progect::Record
    # Base Record object - delegates to record type
      specific to a particular database version,
      e.g. Palm::Progect::DB_18::Record

    # provides class methods to deal with categories:

    set_categories(@categories) # where @categories is a list of appinfo-style
                                # hashrefs in the form of:

lib/Palm/Progect.pm  view on Meta::CPAN

directly from the C<Palm::Progect> module.

Although the various database drivers and record converters all live in
their own Perl modules, C<Palm::Progect> is the interface to their
functionality.  It will transparently delegate to the appropriate module
behind the scenes necessary.

You can load a C<Palm::Progect> database from a Progect C<PDB> file (via
the C<load_db> method), or import records and/or preferences from
another format (such as Text or CSV) (via the C<import_records> and
C<import_prefs> methods).

After a Progect database has been loaded or imported, you will have
a list of records (in C<$progect-E<gt>records>), and a preferences object
(in C<$progect-E<gt>preferences>).

Each record in C<$progect-E<gt>records> is an object of type
L<Palm::Progect::Record>.

    for my $rec (@{ $progect->records }) {
        my $description = $rec->description;
        my $priority    = $rec->priority;
        print "[$priority] $description\n";
    }

See L<Palm::Progect::Record> for the format of these records.

Once you have loaded the records and preferences, you can save them
to a Progect C<PDB> file (via the C<save_db> method), or export
them to another format (such as Text or CSV), via the C<export_records>
and C<export_prefs> methods.

Currently the C<Preferences> interface is not well defined and is
mainly there to allow for future development.  See L<BUGS and CAVEATS>.

This module was largely written in support of the B<progconv> utility,
which is a conversion utility which imports and exports between
Progect PDB files and other formats.

=head2 Constructor

lib/Palm/Progect.pm  view on Meta::CPAN


=head2 Methods

=over 4

=item records

A reference to the list of records within the database.  Each record
is an object of type C<Palm::Progect::Record>.

=item prefs

A reference to the preferences object within the database.  It is an
object of type C<Palm::Progect::Prefs>.  For now the prefs object
doesn't do very much and is mostly a placeholder to allow for future
development.

=item options

Reference to the hash of user options passed to the C<new> constructor.
See the C<new> constructor for details.

=item version

lib/Palm/Progect.pm  view on Meta::CPAN

=end internal_use_only

=cut

use CLASS;
use base qw(Class::Accessor Class::Constructor);

my @Accessors = qw(
    _palm_pdb
    records
    prefs
    options
    version
);

CLASS->mk_accessors(@Accessors);
CLASS->mk_constructor(
    Auto_Init    => \@Accessors,
    Init_Methods => '_init',
);

lib/Palm/Progect.pm  view on Meta::CPAN

        $appinfo = {
            'categories' => [],
            'other'      => pack('C', 23),
        };
    }

    my $version = unpack 'C', $appinfo->{'other'};
    print STDERR "Progect database is version $version\n" unless $self->options->{'quiet'};

    # Allow the user to manually override the version
    # (after all, the database prefs might be corrupt)
    if ($args{version} and $version != $args{version}) {
        $version = $args{version};
        print STDERR "Forcing version to $version\n" unless $self->options->{'quiet'};
    }

    my @raw_records = @{ $self->_palm_pdb->{'records'} };

    # Categories will always be a list of unique names
    my @categories  = @{$appinfo->{'categories'}};

lib/Palm/Progect.pm  view on Meta::CPAN

    for my $raw_record (@raw_records) {
        my $record = Palm::Progect::Record->new(
            version    => $version,
            raw_record => $raw_record,
        );

        push @records, $record;
    }

    # This doesn't do much at present
    my $prefs  = Palm::Progect::Prefs->new(
        version    => $version,
        appinfo    => $appinfo,
        name       => _db_name_from_filename($file),
    );
    $prefs->categories(@categories);

    $self->records(@records);
    $self->prefs($prefs);
    $self->version($version);
}

=item save_db(file =E<gt> $filename, version =E<gt> $version)

Save the records and prefs as a Progect database of version C<$version>
to the filename C<$filename>.

If you do not specify a version then the latest available version is
assumed, unless you have set C<version> before, by a previous call
to C<load_db> or C<save_db>.

Currently supported versions are C<18> (for Progect database version 0.18) and
C<23> (for Progect database version 0.23).

Progect database version 0.18 was used all the way up until Progect version

lib/Palm/Progect.pm  view on Meta::CPAN

    for my $record (@records) {

        my $new_record = Palm::Progect::Record->new(
            version     => $save_version,
            from_record => $record,
        );

        push @raw_records, $new_record->raw_record;
    }

    # Use our prefs object, if it exists.
    # Otherwise, create a new one.

    my $prefs = $self->prefs;

    $prefs = Palm::Progect::Prefs->new(
        version    => $save_version,
        from_prefs => $self->prefs,
    );
    $self->prefs($prefs);

    # Fetch the final category list from the Record object
    my @categories = Palm::Progect::Record::get_categories();

    # Pack the categories into the prefs
    $prefs->categories(@categories);
    $prefs->name(_db_name_from_filename($file));

    # $version is now our preferred db version
    $self->version($save_version);

    # Save our records
    $self->records(\@raw_records);

    # put @raw_records, $raw_prefs, and some constant stuff into $self->_palm_pdb

    $self->_palm_pdb->{'records'}                = \@raw_records;
    $self->_palm_pdb->{'appinfo'}                = $prefs->packed_appinfo;

    $self->_palm_pdb->{'creator'}                = 'lbPG';
    $self->_palm_pdb->{'type'}                   = "DATA";
    $self->_palm_pdb->{'attributes'}{'resource'} = 0;

    # This may move to Palm::Progect::Prefs eventually...
    $self->_palm_pdb->{'name'}                   = $prefs->name;

    # Finally, write the pdb file
    print STDERR "Saving Progect database in version $save_version to $file\n" unless $self->options->{'quiet'};
    $self->_palm_pdb->Write($file);
}

=item import_records(%args)

Import records from a file.

lib/Palm/Progect.pm  view on Meta::CPAN


    my $file   = delete $args{'file'};
    my $append = delete $args{'append'};

    my $converter = Palm::Progect::Converter->new(
        %args,
    );

    $converter->load_records($file, $append);
    $self->records($converter->records);
    $self->prefs($converter->prefs);
}

=item export_records(%args)

Export records to a file.

The options passed in C<%args> are as follows:

=over 4

lib/Palm/Progect.pm  view on Meta::CPAN

sub export_records {
    my $self = shift;
    my %args = @_;

    my $file   = delete $args{'file'};
    my $append = delete $args{'append'};

    my $converter = Palm::Progect::Converter->new(
        %args,
        records => $self->records,
        prefs   => $self->prefs,
    );

    $converter->save_records($file, $append);
}

=item import_prefs

Import preferences from a file.  Currently this is not supported.

=cut

sub import_prefs {
    my $self = shift;
    my %args = @_;
}

=item export_prefs

Export preferences to a file.  Currently this is not supported.

=cut

sub export_prefs {
    my $self = shift;
    my %args = @_;
}

=item repair_tree

Goes through the list of records and repairs the relationships between them:

    $progect->repair_tree;

lib/Palm/Progect/Converter.pm  view on Meta::CPAN


See also the individual converter objects.

=cut

use CLASS;
use base 'Class::Accessor';

my @Accessors = qw(
    records
    prefs
    quiet
);

CLASS->mk_accessors(@Accessors);

# Delegate to Palm::Progect::Converter::CSV, Palm::Progect::Converter::HTML, etc.

sub new {
    my $proto      = shift;
    my $this_class = ref $proto || $proto;

lib/Palm/Progect/Converter/Text.pm  view on Meta::CPAN


        print FH "${record_indent}", join ' ', @line;

        print FH "\n";
    }
    print FH "\n";

    close FH;
}

sub load_prefs {
}

sub save_prefs {
}

sub _expand_tabs {
    my ($string, $tabstop) = @_;
    $string =~ s/\t/' ' x $tabstop/ge;
    return $string;
}

sub _trim_lines {
    my ($whitespace, $tabstop, @lines) = @_;

lib/Palm/Progect/DB_18/Prefs.pm  view on Meta::CPAN


sub packed_appinfo {
    my $self = shift;

    return &Palm::StdAppInfo::pack_StdAppInfo($self->{'appinfo'});
}

sub _seed_appinfo {
    my $self = shift;

    my $progect_prefs = pack 'C', 18;

    my $appinfo = {
        sortOrder       => undef,
        other           => $progect_prefs,
    };

    &Palm::StdAppInfo::seed_StdAppInfo($appinfo);
    $self->appinfo($appinfo);
}

1;

lib/Palm/Progect/DB_23/Prefs.pm  view on Meta::CPAN

    my $self = shift;

    return &Palm::StdAppInfo::pack_StdAppInfo($self->{'appinfo'});
}

sub _seed_appinfo {
    my $self = shift;

    my $progect_version = 23;

    # This interpretation of the prefs format is
    # NOT correct.  It is here to make sure that Progect
    # gets *something* in the database's prefs block.
    # Otherwise it assumes all sorts of wonky defaults.
    #
    # But currently setting (e.g.) the displayDueDates bit
    # will fubar all the prefs.


    #             ver    1  1  1  1  1  1  1  1  2  2
    # 0e 0f 0f 00 17 00 00 01 01 00 00 01 01 02 03 01 |................|
    #  2  2  2  2  2  2  t  .  .  . p. c.  .  .  .  ?
    # 01 00 00 00 00 00 00 00 10 06 06 00 00 00 00 04 |................|
    #  ?  ?  ?  ?  ?  ?  ?  3  3  3  c  c  4  4
    # 54 1c 00 04 54 1c 02 07 01 00 ff ff 02 01       |T...T.........  |


    my $progect_prefs = pack 'CC'           # version, reserved
                           . 'CCCC CCCC'    # first prefs group
                           . 'CCCC CCCC'    # second prefs group
                           . 'CCC CC C CC'  # task defaults
                           . 'CCC CCC CCC'  # padding ???

                           . 'CCC'        # third prefs group
                           . 'CC'         # flat categories 1 & 2
                           . 'CC',        # fourth prefs group


                        $progect_version,
                        0,   # reserved

                        ## first prefs group
                        0,   # hide done tasks
                        1,   # displayDueDates
                        1,   # displayPriorities
                        0,   # displayYear

                        0,   # useFatherStatus
                        1,   # autoSyncToDo
                        1,   # flatHideDone
                        2,   # flat_dated

                        ## second prefs group
                        3,   # flat_min_priority
                        1,   # flatOr
                        1,   # flatMin
                        0,   # boldMinPriority

                        0,   # boldMinDays
                        0,   # strikeDoneTasks
                        0,   # hideDoneProgress
                        0,   # hideProgress

lib/Palm/Progect/DB_23/Prefs.pm  view on Meta::CPAN

                            #
                            # 6, # priority
                            # 0, # completed
                            #
                            # 0, # date 1
                            # 0, # date 2
                            # 0, # date 3
                            # 0, # desc
                            # 0, # reserved (align)

                        ## third prefs group
                        0,   # flatSorted
                        0,   # flatDateLimit
                        1,   # completionDate

                        255, # flatCategories1
                        255, # flatCategories2

                        ## fourth prefs group
                        2,   # wordWrapLines
                        1;   # drawTreeLines

    my $appinfo = {
        sortOrder  => undef,
        other      => $progect_prefs,
    };

    &Palm::StdAppInfo::seed_StdAppInfo($appinfo);
    $self->appinfo($appinfo);
}

1;

lib/Palm/Progect/Prefs.pm  view on Meta::CPAN


=cut

use base 'Palm::Progect::VersionDelegator';

1;

__END__


Ideas for importing/exporting prefs in various formats:

text format:

    pref: name: value

html format:

    <!-- prefs

    pref: name: value

    -->

csv format:

    pref_name, pref_value


t/pod-coverage.t  view on Meta::CPAN

);

pod_coverage_ok(
          "Palm::Progect::VersionDelegator",
        { also_private => [ qr/^new$/ ], },
        "Palm::Progect::VersionDelegator POD coverage",
);

pod_coverage_ok(
          "Palm::Progect::Converter::Text",
        { also_private => [ qr/^(accepted_extensions)|(dummy)|(load_prefs)|(options_spec)|(provides_export)|(provides_import)|(save_prefs)$/ ], },
        "Palm::Progect::Converter::Text POD coverage",
);

pod_coverage_ok(
          "Palm::Progect::Converter::CSV",
        { also_private => [ qr/^(accepted_extensions)|(options_spec)|(provides_export)|(provides_import)$/ ], },
        "Palm::Progect::Converter::CSV POD coverage",
);

todo.txt  view on Meta::CPAN

  - short-form
  - underline-headings
  - split-by-date
  - undated-heading
  - auto-link-dated
  - smart-date-headings

* Fix Categories (2.0.?)
  - better docs for categories in Record.pm

* Load prefs in DB modules (2.1.?)

* Import/Export prefs in Converter modules (2.?.?)

* VersionDelegator to handle different versions for Prefs and Records
  (e.g. Given version "30", it would delegate to Prefs v0.30 and
  Records v0.23).  This will be necessary the next time the prefs
  format changes but the Record format stays the same.

* require p5-palm 1.2.4

* add 'id' field to the database/converter objects, as per Danny O'Brien's
  request:

    One minor change I did make to the code (in an awfully hacky way, I'm afraid)
    was reflect up the 'id' value of the raw record into
    Palm::Progect::DB_*::Record classes. The id field is useful if you're doing



( run in 2.146 seconds using v1.01-cache-2.11-cpan-0bb4e1dffa6 )