Changeset 3501 for lang/perl/Text-Darts

Show
Ignore:
Timestamp:
12/24/07 01:33:35 (6 years ago)
Author:
dankogai
Message:

v0.02; practical enough to PAUSE?

Location:
lang/perl/Text-Darts/trunk
Files:
1 added
5 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Text-Darts/trunk/Changes

    r3500 r3501  
    11# Revision history for Perl extension Text::Darts. 
    22# 
    3 # $Id: Changes,v 0.1 2007/12/23 15:27:34 dankogai Exp dankogai $ 
     3# $Id: Changes,v 0.2 2007/12/23 16:32:49 dankogai Exp dankogai $ 
    44# 
     5$Revision: 0.2 $ $Date: 2007/12/23 16:32:49 $ 
     6! Darts.xs lib/Text/Darts.pm 
     7  added $td->open(); 
     8 
    590.01  Sun Dec 23 19:26:55 2007 
    610        - original version; created by h2xs 1.23 with options 
  • lang/perl/Text-Darts/trunk/Darts.xs

    r3500 r3501  
    2525int da_free(int dpi){ 
    2626    delete INT2PTR(Darts::DoubleArray *, dpi); 
     27} 
     28 
     29int da_open(char *filename){ 
     30    Darts::DoubleArray *dp = new Darts::DoubleArray; 
     31    if (dp->open(filename) == -1){ 
     32        delete dp; 
     33        return 0; 
     34    } 
     35    return PTR2IV(dp); 
    2736} 
    2837 
     
    106115    RETVAL 
    107116 
     117int 
     118xs_open(filename) 
     119   char *filename 
     120CODE: 
     121   RETVAL = da_open(filename); 
     122OUTPUT: 
     123   RETVAL 
    108124 
    109125SV * 
  • lang/perl/Text-Darts/trunk/MANIFEST

    r3500 r3501  
    11Changes 
    22Darts.xs 
     3MANIFEST 
    34Makefile.PL 
    4 MANIFEST 
    55README 
     6lib/Text/Darts.pm 
    67t/Text-Darts.t 
    7 lib/Text/Darts.pm 
     8t/benchmark.t 
  • lang/perl/Text-Darts/trunk/Makefile.PL

    r3500 r3501  
    11# 
    2 # $Id: Makefile.PL,v 0.1 2007/12/23 15:27:34 dankogai Exp dankogai $ 
     2# $Id: Makefile.PL,v 0.1 2007/12/23 15:27:34 dankogai Exp $ 
    33# 
    44use 5.008001; 
  • lang/perl/Text-Darts/trunk/lib/Text/Darts.pm

    r3500 r3501  
    33use warnings; 
    44use Carp; 
    5 our $VERSION = sprintf "%d.%02d", q$Revision: 0.1 $ =~ /(\d+)/g; 
     5our $VERSION = sprintf "%d.%02d", q$Revision: 0.2 $ =~ /(\d+)/g; 
    66our $DEBUG = 0; 
    77 
     
    1212    my $pkg = shift; 
    1313    my $dpi = xs_make([sort @_]); 
     14    bless \$dpi, $pkg; 
     15} 
     16 
     17sub open{ 
     18    my $pkg = shift; 
     19    my $filename = shift; 
     20    my $dpi = xs_open($filename)  
     21        or carp __PACKAGE__, " cannot open $filename"; 
    1422    bless \$dpi, $pkg; 
    1523} 
     
    4250    my @a = ("ALGOL", "ANSI", "ARCO",  "ARPA", "ARPANET", "ASCII"); 
    4351    my $da = __PACKAGE__->new(@a); 
    44     say $da->gsub("I don't like ALGOL at all!", sub{"<<$_[0]>>"}); 
     52    say $da->gsub("I don't like ALGOL at all!", sub{"<$_[0]>"}); 
    4553    say $da->gsub("I don't like nomatch at all!"); 
     54    $da = __PACKAGE__->open(shift); 
     55    say $da->gsub("The quick brown fox jumps over the black lazy dog", 
     56                  sub{"<$_[0]>"}); 
    4657} 
    4758 
     
    6071  my $newstr = $td->gsub("ARPANET is a net by ARPA", sub{ "<<$_[0]>>" }); 
    6172  $newstr is now "<<ARPANET>> is a net by <<ARPA>>". 
     73  # or 
     74  my $td     = Text::Darts->open("words.darts"); 
     75  my $newstr = $td->gsub($str, sub{  
     76     qq(<a href="http://dictionary.com/browse/$_[0]">$_[0]</a>) 
     77  }); # link'em all! 
    6278 
    6379=head1 DESCRIPTION