From 2f69e47db3f927d8a5d55a5f86758cad4c0095da Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sun, 12 Aug 2012 07:21:10 -0400 Subject: Add generic new(). Make properties read-only. --- (limited to 'scripts/MarkdownBook') 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; -- cgit v0.9.1