diff options
author | P. J. McDermott <pjm@nac.net> | 2012-08-12 07:21:10 (EDT) |
---|---|---|
committer | P. J. McDermott <pjm@nac.net> | 2012-08-12 07:21:10 (EDT) |
commit | 2f69e47db3f927d8a5d55a5f86758cad4c0095da (patch) | |
tree | 0b55e571f212e969ce86b0752897022d1f34ceb5 | |
parent | 83d3bb75878bee6ff6f2728ef55735d9fa4b0611 (diff) |
Add generic new(). Make properties read-only.
-rw-r--r-- | scripts/MarkdownBook/Section.pm | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/scripts/MarkdownBook/Section.pm b/scripts/MarkdownBook/Section.pm index 7eb441c..c19a0d0 100644 --- a/scripts/MarkdownBook/Section.pm +++ b/scripts/MarkdownBook/Section.pm @@ -18,34 +18,42 @@ use warnings; package MarkdownBook::Section; +sub new +{ + my ($class, $doc, $num, $id, $title) = @_; + my $self; + + $class = ref($class) || $class; + $self = {}; + bless($self, $class); + + $self->{'document'} = $doc; + $self->{'number'} = $num; + $self->{'id'} = $id; + $self->{'title'} = $title; + + return $self; +} + sub number { my ($self, $number) = @_; - my $old = $self->{'number'}; - - $self->{'number'} = $number if defined($number); - return $old; + return $self->{'number'}; } sub id { my ($self, $id) = @_; - my $old = $self->{'id'}; - $self->{'id'} = $id if defined($id); - - return $old; + return $self->{'id'}; } sub title { my ($self, $title) = @_; - my $old = $self->{'title'}; - - $self->{'title'} = $title if defined($title); - return $old; + return $self->{'title'}; } 1; |