package Student; use strict; use warnings; use Carp; use Person; our @ISA = qw/Person/; =head1 Name Student.pm - a simple class to define a Student, based on Person.pm =head1 Description This is a simple class which inherits from Person. In addition to whatever properties a Person has, a Student will have an Id and a GPA. =head1 Synopsis #!/usr/bin/env perl use strict; use warnings; use Student; my $s1 = new Student('John Smith', '016-32-9823', '337'); $s1->name('John Q. Smith'); my $ss = $s1->SSN(); my $id = $s1->id(); $s1->GPA(65.0); $s1->show(); print "Student: $s1 is currently: ", $s1->status(), "\n"; __END__ =head1 Subroutines In addition to any subroutines created by the Person class, the following subroutines are created for Student objects. =head2 new Constructor. Creates a Person object, and then sets the additional id attribute. Takes three arguments (the first two defined by Person). =cut sub new { my $class = shift; #create the base Person object my $self = $class->SUPER::new(@_); #set additional attributes: carp "No id passed, using undef" unless @_ >= 3; $self->{id} = $_[2]; #Bless the object into its new class, and return it. bless $self, $class; } =head2 id Id accessor. Gets and Sets the id. =cut sub id { my $self = shift; $self->{id} = shift if @_; return $self->{id}; } =head2 GPA GPA accessor. Gets and Sets the GPA. =cut sub GPA { my $self = shift; $self->{GPA} = shift if @_; return $self->{GPA}; } =head2 status Returns whether or not this student is passing or failing. =cut sub status { my $self = shift; $self->{GPA} >= 65 ? 'passing' : 'failing'; } =head1 See Also L class. =head1 Copyright Copyright 2005, Paul Lalli. This file is freely distributed and may be used or modified for any purposes. No warranties are expressed or implied. To contact the author, email lallip AT cs DOT rpi DOT edu =cut 1;