# $Id: Job.pm 97 2005-11-15 15:22:35Z daisuke $ # # Copyright (c) 2005 Daisuke Maki # All rights reserved. package Xango::Job; use strict; use URI; sub new { my $class = shift; my %args = @_; my $self = bless {notes => {}}, $class; $self->id(delete $args{id}); $self->uri(delete $args{uri}); while (my($k, $v) = each %args) { $v = URI->new($v) if ($k eq 'uri'); $self->notes($k, $v); } return $self; } sub _elem { my $self = shift; my $field = shift; my $ret = $self->{$field}; if (@_) { $self->{$field} = shift } if (wantarray) { (ref($ret) eq 'ARRAY') ? @$ret : (ref($ret) eq 'HASH') ? %$ret : $ret; } else { return $ret; } } sub id { shift->_elem('id', @_) } sub uri { shift->_elem('uri', @_) } sub _notes { shift->_elem('notes', @_) } sub notes { my $self = shift; my $field = shift; my $notes = $self->_notes(); my $ret = $notes->{$field}; if (@_) { $notes->{$field} = shift } if (wantarray) { (ref($ret) eq 'ARRAY') ? @$ret : (ref($ret) eq 'HASH') ? %$ret : $ret; } else { return $ret; } } 1; __END__ =head1 NAME Xango::Job - Xango Job =head1 SYNOPSIS use Xango::Job; my $job = Xango::Job->new(uri => $uri, foo => $foo, bar => $bar); =head1 DESCRIPTION For backwards compatibility (and a little bit for flexibility), all 'job' instances should be a hashref. But it's up to you to define what a job is. Newer modules should be using the notes() function to store arbitrary data. =head1 METHODS =head2 new(uri =E $uri, [key =E $value, key =E $value, ...]) Create a new Xango::Job object. =head2 id =head2 uri =head2 notes($key[, $value]) =head1 AUTHOR Copyright 2005 Daisuke Maki Edmaki@cpan.orgE. All rights reserved. Development funded by Brazil, Ltd. Ehttp://b.razil.jpE =cut