summaryrefslogtreecommitdiff
path: root/t/Simple.pm
blob: 1b417df843f1d89dbdda5df87a7108b2dc70b201 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package Simple; 
use strict;
use warnings;
 
use Class::XPath
  get_name => 'name',
  get_parent => 'parent',
  get_root   => 'root',
  get_children => 'kids',               
  get_attr_names => 'param',
  get_attr_value => 'param',
  get_content    => 'data';
 
 
sub name   shift->{name} }
sub parent shift->{parent} }
sub root   local $_=shift
             while($_->{parent}) { $_ = $_->{parent} }
             return $_; }
sub param if (@_ == 2) { return $_[0]->{$_[1]} } 
            else { return qw(foo bar baz) } }
sub data shift->{data} }
sub kids { @{shift->{kids}} }
 
sub new_root my $pkg = shiftbless({kids => [], @_}, $pkg); }
sub add_kid my $self = shift
              push(@{$self->{kids}}, 
                  bless({kids => [], @_parent => $self }, ref $self));
              $self->{kids}[-1]; }
                 
1;