1package XML::FOAF::Person; 2use strict; 3 4use RDF::Core::Resource; 5 6sub new { 7 bless { foaf => $_[1], subject => $_[2] }, $_[0]; 8} 9 10sub knows { 11 my $person = shift; 12 my $knows = RDF::Core::Resource->new($XML::FOAF::NAMESPACE . 'knows'); 13 my $enum = $person->{foaf}->{model}->getStmts($person->{subject}, $knows); 14 my $stmt = $enum->getFirst; 15 my @knows; 16 while (defined $stmt) { 17 push @knows, XML::FOAF::Person->new($person->{foaf}, $stmt->getObject); 18 $stmt = $enum->getNext; 19 } 20 \@knows; 21} 22 23sub get { 24 my $person = shift; 25 my($what) = @_; 26 unless ($what =~ /:/) { 27 $what = $XML::FOAF::NAMESPACE . $what; 28 } 29 my $res = RDF::Core::Resource->new($what); 30 my $enum = $person->{foaf}->{model}->getStmts($person->{subject}, $res); 31 my $stmt = $enum->getFirst or return undef; 32 $stmt->getObject->getLabel; 33} 34 35sub DESTROY { } 36 37use vars qw( $AUTOLOAD ); 38sub AUTOLOAD { 39 (my $var = $AUTOLOAD) =~ s!.+::!!; 40 no strict 'refs'; 41 *$AUTOLOAD = sub { $_[0]->get($var) }; 42 goto &$AUTOLOAD; 43} 44 451; 46__END__ 47 48=head1 NAME 49 50XML::FOAF::Person - A Person class in a FOAF file 51 52=head1 SYNOPSIS 53 54 my $foaf = XML::FOAF->new(URI->new('http://foo.com/my.foaf')); 55 my $person = $foaf->person; 56 print $person->mbox, "\n"; 57 my $people = $foaf->knows; 58 59=head1 DESCRIPTION 60 61I<XML::FOAF::Person> represents a I<Person> class in a FOAF file. 62 63=head1 USAGE 64 65You can use any property as a method name and call it on a I<XML::FOAF::Person> 66object. For example: 67 68 my $email = $person->mbox; 69 my $name = $person->name; 70 71In addition to this, some methods with special beheavior are defined below: 72 73=head2 $person->knows 74 75Returns a reference to an array of I<XML::FOAF::Person> objects representing 76the people that I<$person> knows. 77 78=head1 AUTHOR & COPYRIGHT 79 80Please see the I<XML::FOAF> manpage for author, copyright, and license 81information. 82 83=cut 84