knu-perlstorable 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/perlstorable.rb +23 -12
 - metadata +1 -1
 
    
        data/lib/perlstorable.rb
    CHANGED
    
    | 
         @@ -23,6 +23,7 @@ module PerlStorable 
     | 
|
| 
       23 
23 
     | 
    
         
             
              #
         
     | 
| 
       24 
24 
     | 
    
         
             
              # call-seq:
         
     | 
| 
       25 
25 
     | 
    
         
             
              #     PerlStorable.thaw(str) => object
         
     | 
| 
      
 26 
     | 
    
         
            +
              #     PerlStorable.load(str) => object
         
     | 
| 
       26 
27 
     | 
    
         
             
              #
         
     | 
| 
       27 
28 
     | 
    
         
             
              # Deserializes a string serialized by Perl's Storable module.
         
     | 
| 
       28 
29 
     | 
    
         
             
              #
         
     | 
| 
         @@ -59,6 +60,10 @@ module PerlStorable 
     | 
|
| 
       59 
60 
     | 
    
         
             
                io.close if need_close
         
     | 
| 
       60 
61 
     | 
    
         
             
              end
         
     | 
| 
       61 
62 
     | 
    
         | 
| 
      
 63 
     | 
    
         
            +
              class << self
         
     | 
| 
      
 64 
     | 
    
         
            +
                alias load thaw
         
     | 
| 
      
 65 
     | 
    
         
            +
              end
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
       62 
67 
     | 
    
         
             
              SX_OBJECT           =  0 # Already stored object
         
     | 
| 
       63 
68 
     | 
    
         
             
              SX_LSCALAR          =  1 # Scalar (large binary) follows (length, data)
         
     | 
| 
       64 
69 
     | 
    
         
             
              SX_ARRAY            =  2 # Array forthcominng (size, item list)
         
     | 
| 
         @@ -374,11 +379,29 @@ module PerlStorable 
     | 
|
| 
       374 
379 
     | 
    
         | 
| 
       375 
380 
     | 
    
         
             
              end
         
     | 
| 
       376 
381 
     | 
    
         | 
| 
      
 382 
     | 
    
         
            +
              # This class represents a Perl scalar value that is immutable in
         
     | 
| 
      
 383 
     | 
    
         
            +
              # Ruby. (most likely an integer)
         
     | 
| 
       377 
384 
     | 
    
         
             
              class PerlScalar
         
     | 
| 
      
 385 
     | 
    
         
            +
                attr_reader :value
         
     | 
| 
      
 386 
     | 
    
         
            +
             
     | 
| 
       378 
387 
     | 
    
         
             
                def initialize(value)
         
     | 
| 
       379 
388 
     | 
    
         
             
                  @value = value
         
     | 
| 
       380 
389 
     | 
    
         
             
                end
         
     | 
| 
       381 
390 
     | 
    
         | 
| 
      
 391 
     | 
    
         
            +
                def to_i
         
     | 
| 
      
 392 
     | 
    
         
            +
                  @value.to_i
         
     | 
| 
      
 393 
     | 
    
         
            +
                end
         
     | 
| 
      
 394 
     | 
    
         
            +
                alias to_int to_i
         
     | 
| 
      
 395 
     | 
    
         
            +
             
     | 
| 
      
 396 
     | 
    
         
            +
                def to_s
         
     | 
| 
      
 397 
     | 
    
         
            +
                  @value.to_s
         
     | 
| 
      
 398 
     | 
    
         
            +
                end
         
     | 
| 
      
 399 
     | 
    
         
            +
                alias to_str to_s
         
     | 
| 
      
 400 
     | 
    
         
            +
             
     | 
| 
      
 401 
     | 
    
         
            +
                def to_f
         
     | 
| 
      
 402 
     | 
    
         
            +
                  @value.to_f
         
     | 
| 
      
 403 
     | 
    
         
            +
                end
         
     | 
| 
      
 404 
     | 
    
         
            +
             
     | 
| 
       382 
405 
     | 
    
         
             
                def inspect
         
     | 
| 
       383 
406 
     | 
    
         
             
                  '#<%s:%s>' % [self.class, @value.inspect]
         
     | 
| 
       384 
407 
     | 
    
         
             
                end
         
     | 
| 
         @@ -414,15 +437,3 @@ module PerlStorable 
     | 
|
| 
       414 
437 
     | 
    
         
             
                obj.is_a?(PerlBlessed)
         
     | 
| 
       415 
438 
     | 
    
         
             
              end
         
     | 
| 
       416 
439 
     | 
    
         
             
            end
         
     | 
| 
       417 
     | 
    
         
            -
             
     | 
| 
       418 
     | 
    
         
            -
            if $0 == __FILE__
         
     | 
| 
       419 
     | 
    
         
            -
              eval DATA.read, nil, $0, __LINE__+4
         
     | 
| 
       420 
     | 
    
         
            -
            end
         
     | 
| 
       421 
     | 
    
         
            -
             
     | 
| 
       422 
     | 
    
         
            -
            __END__
         
     | 
| 
       423 
     | 
    
         
            -
             
     | 
| 
       424 
     | 
    
         
            -
            # TODO: Real tests needed
         
     | 
| 
       425 
     | 
    
         
            -
             
     | 
| 
       426 
     | 
    
         
            -
            require 'pp'
         
     | 
| 
       427 
     | 
    
         
            -
            obj = PerlStorable.thaw(ARGF.read)
         
     | 
| 
       428 
     | 
    
         
            -
            pp obj
         
     |