[BACK]Return to Todo.pm CVS log [TXT][DIR] Up to [local] / todotxt / Text-Todo / lib / Text

Annotation of todotxt/Text-Todo/lib/Text/Todo.pm, Revision 1.2

1.1       andrew      1: package Text::Todo;
                      2:
1.2     ! andrew      3: # $RedRiver: Todo.pm,v 1.1.1.1 2009/07/09 18:21:34 andrew Exp $
1.1       andrew      4:
                      5: use warnings;
                      6: use strict;
                      7: use Carp;
                      8:
1.2     ! andrew      9: use Class::Std::Utils;
        !            10: use Text::Todo::Entry;
        !            11:
1.1       andrew     12: use version; our $VERSION = qv('0.0.1');
                     13:
1.2     ! andrew     14: {
        !            15:
        !            16:     my %file_of;
        !            17:     my %list_of;
1.1       andrew     18:
1.2     ! andrew     19:     sub new {
        !            20:         my ( $class, $file ) = @_;
1.1       andrew     21:
1.2     ! andrew     22:         my $self = bless anon_scalar(), $class;
        !            23:         my $ident = ident($self);
        !            24:
        !            25:         $file_of{$ident} = $file;
        !            26:
        !            27:         if ($file) {
        !            28:             $self->load;
        !            29:         }
        !            30:
        !            31:         return $self;
        !            32:     }
        !            33:
        !            34:     sub load {
        !            35:         my ( $self, $file ) = @_;
        !            36:         my $ident = ident($self);
        !            37:
        !            38:         if ($file) {
        !            39:             $file_of{$ident} = $file;
        !            40:         }
        !            41:         else {
        !            42:             $file = $file_of{$ident};
        !            43:         }
        !            44:
        !            45:         croak 'load requires a filename' if !$file;
        !            46:
        !            47:         my @list;
        !            48:         open my $fh, '<', $file or croak "Couldn't open [$file]: $!";
        !            49:         while (<$fh>) {
        !            50:             s/\r?\n$//xms;
        !            51:             push @list, Text::Todo::Entry->new($_);
        !            52:         }
        !            53:         close $fh or croak "Couldn't close [$file]: $!";
        !            54:         $list_of{$ident} = \@list;
        !            55:
        !            56:         return 1;
        !            57:     }
        !            58:
        !            59:     sub save {
        !            60:         my ( $self, $file ) = @_;
        !            61:         my $ident = ident($self);
        !            62:
        !            63:         if ($file) {
        !            64:             $file_of{$ident} = $file;
        !            65:         }
        !            66:         else {
        !            67:             $file = $file_of{$ident};
        !            68:         }
        !            69:
        !            70:         croak 'save requires a filename' if !$file;
        !            71:
        !            72:         open my $fh, '>', $file or croak "Couldn't open [$file]: $!";
        !            73:         foreach my $e ( @{ $list_of{$ident} } ) {
        !            74:             print $e->text . "\n" or croak "Couldn't print to [$file]: $!";
        !            75:         }
        !            76:         close $fh or croak "Couldn't close [$file]: $!";
        !            77:
        !            78:         return 1;
        !            79:     }
        !            80:
        !            81:     sub list {
        !            82:         my ($self) = shift;
        !            83:         my $ident = ident($self);
        !            84:         return if !$list_of{$ident};
        !            85:
        !            86:         return $list_of{$ident};
        !            87:
        !            88:         #my $id = 1;
        !            89:         #my @l;
        !            90:         #foreach my $e ( @{ $list_of{$ident} } ) {
        !            91:         #    push @l, $e; #{ %{$e}, id => $id };
        !            92:         #    $id++;
        !            93:         #}
        !            94:         #
        !            95:         #my @list = sort { $a->priority cmp $b->priority }
        !            96:         #    grep { defined $_->priority } @l;
        !            97:         #
        !            98:         #push @list, grep { !defined $_->priority } @l;
        !            99:         #
        !           100:         #return \@list;
        !           101:     }
1.1       andrew    102:
1.2     ! andrew    103: }
1.1       andrew    104:
1.2     ! andrew    105: 1;    # Magic true value required at end of module
1.1       andrew    106: __END__
                    107:
                    108: =head1 NAME
                    109:
                    110: Text::Todo - [One line description of module's purpose here]
                    111:
                    112:
                    113: =head1 VERSION
                    114:
                    115: This document describes Text::Todo version 0.0.1
                    116:
                    117:
                    118: =head1 SYNOPSIS
                    119:
                    120:     use Text::Todo;
                    121:
                    122: =for author to fill in:
                    123:     Brief code example(s) here showing commonest usage(s).
                    124:     This section will be as far as many users bother reading
                    125:     so make it as educational and exeplary as possible.
                    126:
                    127:
                    128: =head1 DESCRIPTION
                    129:
                    130: =for author to fill in:
                    131:     Write a full description of the module and its features here.
                    132:     Use subsections (=head2, =head3) as appropriate.
                    133:
                    134:
                    135: =head1 INTERFACE
                    136:
                    137: =for author to fill in:
                    138:     Write a separate section listing the public components of the modules
                    139:     interface. These normally consist of either subroutines that may be
                    140:     exported, or methods that may be called on objects belonging to the
                    141:     classes provided by the module.
                    142:
1.2     ! andrew    143: =head2 new
        !           144:
        !           145: =head2 load
        !           146:
        !           147: =head2 save
        !           148:
        !           149: =head2 list
1.1       andrew    150:
                    151: =head1 DIAGNOSTICS
                    152:
                    153: =for author to fill in:
                    154:     List every single error and warning message that the module can
                    155:     generate (even the ones that will "never happen"), with a full
                    156:     explanation of each problem, one or more likely causes, and any
                    157:     suggested remedies.
                    158:
                    159: =over
                    160:
                    161: =item C<< Error message here, perhaps with %s placeholders >>
                    162:
                    163: [Description of error here]
                    164:
                    165: =item C<< Another error message here >>
                    166:
                    167: [Description of error here]
                    168:
                    169: [Et cetera, et cetera]
                    170:
                    171: =back
                    172:
                    173:
                    174: =head1 CONFIGURATION AND ENVIRONMENT
                    175:
                    176: =for author to fill in:
                    177:     A full explanation of any configuration system(s) used by the
                    178:     module, including the names and locations of any configuration
                    179:     files, and the meaning of any environment variables or properties
                    180:     that can be set. These descriptions must also include details of any
                    181:     configuration language used.
                    182:
                    183: Text::Todo requires no configuration files or environment variables.
                    184:
                    185:
                    186: =head1 DEPENDENCIES
                    187:
                    188: =for author to fill in:
                    189:     A list of all the other modules that this module relies upon,
                    190:     including any restrictions on versions, and an indication whether
                    191:     the module is part of the standard Perl distribution, part of the
                    192:     module's distribution, or must be installed separately. ]
                    193:
                    194: None.
                    195:
                    196:
                    197: =head1 INCOMPATIBILITIES
                    198:
                    199: =for author to fill in:
                    200:     A list of any modules that this module cannot be used in conjunction
                    201:     with. This may be due to name conflicts in the interface, or
                    202:     competition for system or program resources, or due to internal
                    203:     limitations of Perl (for example, many modules that use source code
                    204:     filters are mutually incompatible).
                    205:
                    206: None reported.
                    207:
                    208:
                    209: =head1 BUGS AND LIMITATIONS
                    210:
                    211: =for author to fill in:
                    212:     A list of known problems with the module, together with some
                    213:     indication Whether they are likely to be fixed in an upcoming
                    214:     release. Also a list of restrictions on the features the module
                    215:     does provide: data types that cannot be handled, performance issues
                    216:     and the circumstances in which they may arise, practical
                    217:     limitations on the size of data sets, special cases that are not
                    218:     (yet) handled, etc.
                    219:
                    220: No bugs have been reported.
                    221:
                    222: Please report any bugs or feature requests to
                    223: C<bug-text-todo@rt.cpan.org>, or through the web interface at
                    224: L<http://rt.cpan.org>.
                    225:
                    226:
                    227: =head1 AUTHOR
                    228:
                    229: Andrew Fresh  C<< <andrew@cpan.org> >>
                    230:
                    231:
                    232: =head1 LICENSE AND COPYRIGHT
                    233:
                    234: Copyright (c) 2009, Andrew Fresh C<< <andrew@cpan.org> >>. All rights reserved.
                    235:
                    236: This module is free software; you can redistribute it and/or
                    237: modify it under the same terms as Perl itself. See L<perlartistic>.
                    238:
                    239:
                    240: =head1 DISCLAIMER OF WARRANTY
                    241:
                    242: BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
                    243: FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
                    244: OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
                    245: PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
                    246: EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
                    247: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
                    248: ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
                    249: YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
                    250: NECESSARY SERVICING, REPAIR, OR CORRECTION.
                    251:
                    252: IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
                    253: WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
                    254: REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
                    255: LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
                    256: OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
                    257: THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
                    258: RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
                    259: FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
                    260: SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
                    261: SUCH DAMAGES.

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>