티스토리 뷰

Code/Study

[PerlNET] CIty (Mix Perl & C#)

Hide Code 2008. 11. 9. 04:02


Program.cs

using System;
using MixPerl;

namespace CityClient
{
    class Program
    {
        static void Main(string[] args)
        {
            City myCity1 = new City("SmallVille", 4);
            City myCity2 = new City("Crowdedburg", 40);
            myCity1.PrintCityInfo(true);
            myCity2.Population = 500000;
            myCity2.PrintCityInfo(false);
        }
    }
}



City.pm

package MixPerl::City;
use strict;
use namespace "System";
use PerlNET qw(AUTOCALL );

#Consturctor
=for interface
  [interface: pure]
  static City(str name, Double population);
=cut

#Properties
=for interface
  str Name;
  Double Population;
=cut

#Methods
=for interface
  void PrintCityInfo(Boolean pretty);
=cut

#Constructor definition
sub new
{
  my $self = shift;
  my ($name, $pop) = @_;
  my $city = {Name => $name, Population => $pop};
  bless $city, $self;
  return $city;
}
#City Name as readonly property
sub Name
{
  my ($self, $val) = @_;
  if (defined $val)
  {
    return; #do nothing, ignore the given value
  }
  else
  {
    $self->{Name}; #Get City Name
  }
}
#Population as read write property
#City Name as readonly property
sub Population
{
  my ($self, $val) = @_;
  if (defined $val)
  {
    $self->{Population} = $val; #Set Population
  }
  else
  {
    $self->{Population};        #Get Population
  }
}
##Print City Info
sub PrintCityInfo
{
  my($self, $val) = @_;
  if ($val eq PerlNET::true)
  {
    print "------------------\n";
  }
  print "City of  $self->{Name}  with " .
        " population of $self->{Population} \n";
  if ($val eq PerlNET::true)
  {
    print "------------------\n\n";
  }
}




'Code > Study' 카테고리의 다른 글

[PerlNET] Regex (Perl C# Mix)  (0) 2008.11.09
[Perl] Cocoa (pl pm sample)  (0) 2008.11.09
[Perl] BeeConverter (Convert HTML Entity to Unicode Character)  (0) 2008.11.09
[C/C++ vs C#] static (1)  (0) 2008.07.16
[C/C++ vs C#] sizeof  (0) 2008.07.16
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함