| WWW-USF-Directory documentation | Contained in the WWW-USF-Directory distribution. |
WWW::USF::Directory::Entry::Affiliation - Information about an affiliation of an entry
Version 0.003
# Print the afflilation say $affiliation; # Does the affiliation have a department? say $affiliation->has_department ? 'yes' : 'no';
Information about an affiliation of an entry. These objects are typically created by WWW::USF::Directory.
This is fully object-oriented, and as such before any method can be used, the constructor needs to be called to create an object to work with.
This will construct a new object.
%attributes is a HASH where the keys are attributes (specified in the
ATTRIBUTES section).
$attributes is a HASHREF where the keys are attributes (specified in the
ATTRIBUTES section).
This is a special case where the $role_department_string is a string that
came from the directory page in the format role \s+ : \s+ department.
This is the department in which the affiliation applies.
Required. This is the role of the affiliation.
This method is used to return a string that will be given when this object is used in a string context. This returns "role: department" or "role".
my $affiliation = WWW::USF::Directory::Entry::Affiliation->new(
role => 'My Role'
department => 'Department'
);
say $affiliation; # Prints "My Role: Department"
Douglas Christopher Wilson, <doug at somethingdoug.com>
Please report any bugs or feature requests to bug-www-usf-directory at rt.cpan.org,
or through the web interface at
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW::USF::Directory.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.
I highly encourage the submission of bugs and enhancements to my modules.
Copyright 2010 Douglas Christopher Wilson.
This program is free software; you can redistribute it and/or modify it under the terms of either:
| WWW-USF-Directory documentation | Contained in the WWW-USF-Directory distribution. |
package WWW::USF::Directory::Entry::Affiliation; use 5.008001; use strict; use warnings 'all'; ########################################################################### # METADATA our $AUTHORITY = 'cpan:DOUGDUDE'; our $VERSION = '0.003'; ########################################################################### # MOOSE use Moose 0.89; use MooseX::StrictConstructor 0.08; ########################################################################### # MOOSE TYPES use MooseX::Types::Common::String qw( NonEmptySimpleStr ); ########################################################################### # ALL IMPORTS BEFORE THIS WILL BE ERASED use namespace::clean 0.04 -except => [qw(meta)]; ########################################################################### # OVERLOADED FUNCTIONS __PACKAGE__->meta->add_package_symbol(q{&()} => sub { }); __PACKAGE__->meta->add_package_symbol(q{&(""} => sub { shift->stringify }); ########################################################################### # ATTRIBUTES has 'department' => ( is => 'ro', isa => NonEmptySimpleStr, documentation => q{The department this role is in}, clearer => '_clear_department', predicate => 'has_department', ); has 'role' => ( is => 'ro', isa => NonEmptySimpleStr, documentation => q{The role of the person in the department}, required => 1, ); ########################################################################### # METHODS sub stringify { # The default stringify method returns role: department or role my ($self) = @_; # Start the string with the role my $string = $self->role; if ($self->has_department) { # Add on the department $string .= ': ' . $self->department; } return $string; } ########################################################################### # CONSTRUCTOR sub BUILDARGS { my ($class, @args) = @_; if (@args == 1 && ref $args[0] eq q{}) { # It looks like a single string was passed to the constructor, so # parse the string. my ($role, $department) = $args[0] =~ m{\A (.+?) (?: \s+ : \s+ (.+?) )? \z}msx; # Set the new arguments with the role @args = (role => $role); if (defined $department) { # Add the department if defined push @args, department => $department; } } # Continue building return $class->SUPER::BUILDARGS(@args); } ########################################################################### # MAKE MOOSE OBJECT IMMUTABLE __PACKAGE__->meta->make_immutable; 1; __END__