develooper Front page | perl.perl5.porters | Postings from November 2000

[PATCH] Class::Struct at compile time

Thread Next
From:
Casey R. Tweten
Date:
November 8, 2000 17:46
Subject:
[PATCH] Class::Struct at compile time
Message ID:
Pine.OSF.4.21.0011082041360.8238-100000@home.kiski.net

Schwern, Damian and I talked about this breifly in New York and
nothing seemed to come of it, so I did it.  ;-)

File::stat was using Class::Struct wrong, so I fixed that too.


*** lib/Class/Struct.pm.orig	Wed Nov  8 20:09:47 2000
--- lib/Class/Struct.pm	Wed Nov  8 20:10:32 2000
***************
*** 14,20 ****
  @ISA = qw(Exporter);
  @EXPORT = qw(struct);
  
! $VERSION = '0.58';
  
  ## Tested on 5.002 and 5.003 without class membership tests:
  my $CHECK_CLASS_MEMBERSHIP = ($] >= 5.003_95);
--- 14,20 ----
  @ISA = qw(Exporter);
  @EXPORT = qw(struct);
  
! $VERSION = '0.59';
  
  ## Tested on 5.002 and 5.003 without class membership tests:
  my $CHECK_CLASS_MEMBERSHIP = ($] >= 5.003_95);
***************
*** 51,56 ****
--- 51,66 ----
      sub DESTROY { }
  }
  
+ sub import {
+     my $self = shift;
+ 
+     if ( @_ ) {
+       &struct;
+     } else {
+       $self->export_to_level( 1, $self, @EXPORT );
+     }
+ }
+ 
  sub struct {
  
      # Determine parameter list structure, one of:
***************
*** 242,248 ****
--- 252,262 ----
              # declare struct, based on array, implicit class name:
      struct( ELEMENT_NAME => ELEMENT_TYPE, ... );
  
+     # Declare struct at compile time
+     use Class::Struct CLASS_NAME => [ ELEMENT_NAME => ELEMENT_TYPE, ... ];
+     use Class::Struct CLASS_NAME => { ELEMENT_NAME => ELEMENT_TYPE, ... };
  
+ 
      package Myobj;
      use Class::Struct;
              # declare struct with four types of elements:
***************
*** 326,332 ****
--- 340,355 ----
  method by that name is explicitly defined; in the latter case, a
  warning is issued if the warning flag (B<-w>) is set.
  
+ =head2 Class Creation at Compile Time
  
+ C<Class::Struct> can create your class at compile time.  The main reason
+ for doing this is obvious, so your class acts like every other class in
+ Perl.  Creating your class at compile time will make the order of events
+ similar to using any other class ( or Perl module ).
+ 
+ There is no significant speed gain between compile time and run time
+ class creation, there is just a new, more standard order of events.
+ 
  =head2 Element Types and Accessor Methods
  
  The four element types -- scalar, array, hash, and class -- are
***************
*** 524,529 ****
--- 547,556 ----
  
  =head1 Author and Modification History
  
+ 
+ Modified by Casey Tweten, 2000-11-08, v0.59.
+ 
+     Added the ability for compile time class creation.
  
  Modified by Damian Conway, 1999-03-05, v0.58.
  




*** lib/File/stat.pm.orig	Wed Nov  8 20:37:01 2000
--- lib/File/stat.pm	Wed Nov  8 20:37:23 2000
***************
*** 20,26 ****
  # Class::Struct forbids use of @ISA
  sub import { goto &Exporter::import }
  
! use Class::Struct qw(struct);
  struct 'File::stat' => [
       map { $_ => '$' } qw{
  	 dev ino mode nlink uid gid rdev size
--- 20,26 ----
  # Class::Struct forbids use of @ISA
  sub import { goto &Exporter::import }
  
! use Class::Struct;
  struct 'File::stat' => [
       map { $_ => '$' } qw{
  	 dev ino mode nlink uid gid rdev size


-- 
print(join(' ', qw(Casey R. Tweten)));my $sig={mail=>'crt@kiski.net',site=>
'http://home.kiski.net/~crt'};print "\n",'.'x(length($sig->{site})+6),"\n";
print map{$_.': '.$sig->{$_}."\n"}sort{$sig->{$a}cmp$sig->{$b}}keys%{$sig};
my $VERSION = '0.01'; #'patched' by Jerrad Pierce <belg4mit at MIT dot EDU>


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About