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

Diff for /todotxt/Text-Todo/lib/Text/Todo.pm between version 1.1 and 1.2

version 1.1, 2009/07/09 19:21:34 version 1.2, 2009/07/10 23:26:14
Line 1 
Line 1 
 package Text::Todo;  package Text::Todo;
   
 # $RedRiver$  # $RedRiver: Todo.pm,v 1.1.1.1 2009/07/09 18:21:34 andrew Exp $
   
 use warnings;  use warnings;
 use strict;  use strict;
 use Carp;  use Carp;
   
   use Class::Std::Utils;
   use Text::Todo::Entry;
   
 use version; our $VERSION = qv('0.0.1');  use version; our $VERSION = qv('0.0.1');
   
 # Other recommended modules (uncomment to use):  {
 #  use IO::Prompt;  
 #  use Perl6::Export;  
 #  use Perl6::Slurp;  
 #  use Perl6::Say;  
   
       my %file_of;
       my %list_of;
   
 # Module implementation here      sub new {
           my ( $class, $file ) = @_;
   
           my $self = bless anon_scalar(), $class;
           my $ident = ident($self);
   
 1; # Magic true value required at end of module          $file_of{$ident} = $file;
   
           if ($file) {
               $self->load;
           }
   
           return $self;
       }
   
       sub load {
           my ( $self, $file ) = @_;
           my $ident = ident($self);
   
           if ($file) {
               $file_of{$ident} = $file;
           }
           else {
               $file = $file_of{$ident};
           }
   
           croak 'load requires a filename' if !$file;
   
           my @list;
           open my $fh, '<', $file or croak "Couldn't open [$file]: $!";
           while (<$fh>) {
               s/\r?\n$//xms;
               push @list, Text::Todo::Entry->new($_);
           }
           close $fh or croak "Couldn't close [$file]: $!";
           $list_of{$ident} = \@list;
   
           return 1;
       }
   
       sub save {
           my ( $self, $file ) = @_;
           my $ident = ident($self);
   
           if ($file) {
               $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]: $!";
           foreach my $e ( @{ $list_of{$ident} } ) {
               print $e->text . "\n" or croak "Couldn't print to [$file]: $!";
           }
           close $fh or croak "Couldn't close [$file]: $!";
   
           return 1;
       }
   
       sub list {
           my ($self) = shift;
           my $ident = ident($self);
           return if !$list_of{$ident};
   
           return $list_of{$ident};
   
           #my $id = 1;
           #my @l;
           #foreach my $e ( @{ $list_of{$ident} } ) {
           #    push @l, $e; #{ %{$e}, id => $id };
           #    $id++;
           #}
           #
           #my @list = sort { $a->priority cmp $b->priority }
           #    grep { defined $_->priority } @l;
           #
           #push @list, grep { !defined $_->priority } @l;
           #
           #return \@list;
       }
   
   }
   
   1;    # Magic true value required at end of module
 __END__  __END__
   
 =head1 NAME  =head1 NAME
Line 56 
Line 140 
     exported, or methods that may be called on objects belonging to the      exported, or methods that may be called on objects belonging to the
     classes provided by the module.      classes provided by the module.
   
   =head2 new
   
   =head2 load
   
   =head2 save
   
   =head2 list
   
 =head1 DIAGNOSTICS  =head1 DIAGNOSTICS
   

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

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