File Coverage

blib/lib/Lisp/Cons.pm
Criterion Covered Total %
statement 15 18 83.3
branch 4 6 66.6
condition n/a
subroutine 5 7 71.4
pod 0 5 0.0
total 24 36 66.6


line stmt bran cond sub pod time code
1             package Lisp::Cons;
2              
3             # Only used to represent (a . b) cons cells. The normal
4             # (a b c d) list is represented with a unblessed array [a,b,c,d]
5              
6 6     6   32 use strict;
  6         12  
  6         331  
7 6     6   31 use vars qw(@EXPORT_OK);
  6         9  
  6         1929  
8              
9             require Exporter;
10             *import = \&Exporter::import;
11             @EXPORT_OK = qw(cons consp);
12              
13             sub cons
14             {
15 0     0 0 0 Lisp::Cons->new(@_);
16             }
17              
18             sub consp
19             {
20 9 100   9 0 93 UNIVERSAL::isa($_[0], "Lisp::Cons") || ref($_[0]) eq "ARRAY";
21             }
22              
23             sub new
24             {
25 0     0 0 0 my($class, $car, $cdr) = @_;
26 0         0 bless [$car, $cdr], $class;
27             }
28              
29             sub car
30             {
31 1     1 0 6 my $self = shift;
32 1         2 my $old = $self->[0];
33 1 50       6 $self->[0] = shift if @_;
34 1         5 $old;
35             }
36              
37             sub cdr
38             {
39 1     1 0 6 my $self = shift;
40 1         2 my $old = $self->[1];
41 1 50       4 $self->[1] = shift if @_;
42 1         4 $old;
43             }
44              
45             1;