version 1.2, 2009/07/10 23:26:14 |
version 1.4, 2010/01/06 20:07:16 |
|
|
package Text::Todo; |
package Text::Todo; |
|
|
# $RedRiver: Todo.pm,v 1.1.1.1 2009/07/09 18:21:34 andrew Exp $ |
# $RedRiver: Todo.pm,v 1.3 2010/01/06 19:54:56 andrew Exp $ |
|
|
use warnings; |
use warnings; |
use strict; |
use strict; |
|
|
my $self = bless anon_scalar(), $class; |
my $self = bless anon_scalar(), $class; |
my $ident = ident($self); |
my $ident = ident($self); |
|
|
$file_of{$ident} = $file; |
if ($file) { $self->load($file); } |
|
|
if ($file) { |
|
$self->load; |
|
} |
|
|
|
return $self; |
return $self; |
} |
} |
|
|
sub load { |
sub file { |
my ( $self, $file ) = @_; |
my ( $self, $file ) = @_; |
my $ident = ident($self); |
my $ident = ident($self); |
|
|
if ($file) { |
if ($file) { |
$file_of{$ident} = $file; |
$file_of{$ident} = $file; |
} |
} |
else { |
|
$file = $file_of{$ident}; |
|
} |
|
|
|
croak 'load requires a filename' if !$file; |
return $file_of{$ident}; |
|
} |
|
|
|
sub load { |
|
my ( $self, $file ) = @_; |
|
my $ident = ident($self); |
|
|
|
$file = $self->file($file) || croak 'load requires a filename'; |
|
|
my @list; |
my @list; |
open my $fh, '<', $file or croak "Couldn't open [$file]: $!"; |
open my $fh, '<', $file or croak "Couldn't open [$file]: $!"; |
while (<$fh>) { |
while (<$fh>) { |
|
|
my ( $self, $file ) = @_; |
my ( $self, $file ) = @_; |
my $ident = ident($self); |
my $ident = ident($self); |
|
|
if ($file) { |
$file = $self->file($file) || croak 'save requires a filename'; |
$file_of{$ident} = $file; |
|
} |
|
else { |
|
$file = $file_of{$ident}; |
|
} |
|
|
|
croak 'save requires a filename' if !$file; |
|
|
|
open my $fh, '>', $file or croak "Couldn't open [$file]: $!"; |
open my $fh, '>', $file or croak "Couldn't open [$file]: $!"; |
foreach my $e ( @{ $list_of{$ident} } ) { |
foreach my $e ( @{ $list_of{$ident} } ) { |
print $e->text . "\n" or croak "Couldn't print to [$file]: $!"; |
print {$fh} $e->text . "\n" |
|
or croak "Couldn't print to [$file]: $!"; |
} |
} |
close $fh or croak "Couldn't close [$file]: $!"; |
close $fh or croak "Couldn't close [$file]: $!"; |
|
|
|
|
} |
} |
|
|
sub list { |
sub list { |
my ($self) = shift; |
my ($self) = @_; |
my $ident = ident($self); |
my $ident = ident($self); |
return if !$list_of{$ident}; |
return if !$list_of{$ident}; |
|
|
|
|
#return \@list; |
#return \@list; |
} |
} |
|
|
|
sub add { |
|
my ( $self, $entry ) = @_; |
|
my $ident = ident($self); |
|
|
|
if ( ref $entry ) { |
|
if ( ref $entry ne 'Text::Todo::Entry' ) { |
|
croak( 'entry is a ' |
|
. ref($entry) |
|
. ' not a Text::Todo::Entry!' ); |
|
} |
|
} |
|
else { |
|
$entry = Text::Todo::Entry->new($entry); |
|
} |
|
|
|
push @{ $list_of{$ident} }, $entry; |
|
|
|
return $entry; |
|
} |
} |
} |
|
|
1; # Magic true value required at end of module |
1; # Magic true value required at end of module |
|
|
|
|
=head1 NAME |
=head1 NAME |
|
|
Text::Todo - [One line description of module's purpose here] |
Text::Todo - Perl interface to todo_txt files |
|
|
|
|
=head1 VERSION |
|
|
|
This document describes Text::Todo version 0.0.1 |
|
|
|
|
|
=head1 SYNOPSIS |
=head1 SYNOPSIS |
|
|
use Text::Todo; |
use Text::Todo; |
|
|
=for author to fill in: |
|
Brief code example(s) here showing commonest usage(s). |
|
This section will be as far as many users bother reading |
|
so make it as educational and exeplary as possible. |
|
|
|
|
|
=head1 DESCRIPTION |
=head1 DESCRIPTION |
|
|
=for author to fill in: |
For more information see L<http://todotxt.com> |
Write a full description of the module and its features here. |
|
Use subsections (=head2, =head3) as appropriate. |
|
|
|
|
|
=head1 INTERFACE |
=head1 INTERFACE |
|
|
=for author to fill in: |
|
Write a separate section listing the public components of the modules |
|
interface. These normally consist of either subroutines that may be |
|
exported, or methods that may be called on objects belonging to the |
|
classes provided by the module. |
|
|
|
=head2 new |
=head2 new |
|
|
=head2 load |
=head2 load |
|
|
=head2 save |
=head2 save |
|
|
|
=head2 file |
|
|
=head2 list |
=head2 list |
|
|
|
=head2 add |
|
|
=head1 DIAGNOSTICS |
=head1 DIAGNOSTICS |
|
|
=for author to fill in: |
=for author to fill in: |
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
=head1 CONFIGURATION AND ENVIRONMENT |
|
|
=for author to fill in: |
|
A full explanation of any configuration system(s) used by the |
|
module, including the names and locations of any configuration |
|
files, and the meaning of any environment variables or properties |
|
that can be set. These descriptions must also include details of any |
|
configuration language used. |
|
|
|
Text::Todo requires no configuration files or environment variables. |
Text::Todo requires no configuration files or environment variables. |
|
|
|
Someday it should be able to read and use the todo.sh config file. |
|
|
|
|
=head1 DEPENDENCIES |
=head1 DEPENDENCIES |
|
|
=for author to fill in: |
=for author to fill in: |
|
|
|
|
=head1 INCOMPATIBILITIES |
=head1 INCOMPATIBILITIES |
|
|
=for author to fill in: |
|
A list of any modules that this module cannot be used in conjunction |
|
with. This may be due to name conflicts in the interface, or |
|
competition for system or program resources, or due to internal |
|
limitations of Perl (for example, many modules that use source code |
|
filters are mutually incompatible). |
|
|
|
None reported. |
None reported. |
|
|
|
|
=head1 BUGS AND LIMITATIONS |
=head1 BUGS AND LIMITATIONS |
|
|
=for author to fill in: |
|
A list of known problems with the module, together with some |
|
indication Whether they are likely to be fixed in an upcoming |
|
release. Also a list of restrictions on the features the module |
|
does provide: data types that cannot be handled, performance issues |
|
and the circumstances in which they may arise, practical |
|
limitations on the size of data sets, special cases that are not |
|
(yet) handled, etc. |
|
|
|
No bugs have been reported. |
No bugs have been reported. |
|
|