home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / private.pm < prev    next >
Encoding:
Perl POD Document  |  2000-12-13  |  2.2 KB  |  108 lines

  1. package private;
  2.  
  3. use strict;
  4.  
  5. use vars qw($VERSION);
  6.  
  7. $VERSION = 0.04;
  8.  
  9. use Class::Fields::Fuxor;
  10. use Class::Fields::Attribs;
  11.  
  12. sub import {
  13.     #Dump the class.
  14.     shift;
  15.     
  16.     my $pack = caller;
  17.     foreach my $field (@_) {
  18.         unless( $field =~ /^_/ ) {
  19.             require Carp;
  20.             Carp::carp("Private data fields should be named with a ",
  21.                        "leading underscore") if $^W;
  22.         }
  23.     }
  24.     add_fields($pack, PRIVATE, @_);
  25. }
  26.  
  27.  
  28. return 'pants of infinity';
  29. __END__
  30. =pod
  31.  
  32. =head1 NAME
  33.  
  34.   private - Add private data members to Perl classes
  35.  
  36.  
  37. =head1 SYNOPSIS
  38.  
  39.   package GI::Joe;
  40.  
  41.   use private qw( _SexualPrefs _IsSpy );
  42.  
  43.   # see the protected man page for an example
  44.  
  45. =head1 DESCRIPTION
  46.  
  47. =over 4
  48.  
  49. =item I<Private member.> 
  50.  
  51. Internal data or functionality.  An attribute or method only directly
  52. accessible to the methods of the same class and inaccessible from any
  53. other scope.  In Perl, notionally private attributes and members are
  54. conventionally given names beginning with an underscore.
  55.  
  56. From B<"Object Oriented Perl"> by Damian Conway
  57.  
  58. =back
  59.  
  60. private.pm adds a list of keys as private data members to the current
  61. class.  See L<public> for more info.
  62.  
  63. Private data members are those pieces of data which are expected to be
  64. only accessed by methods of the class which owns them.  They are not
  65. inherited by subclasses.
  66.  
  67. private.pm serves a subset of the functionality of fields.pm.
  68.  
  69.   use private qw(_Foo);
  70.  
  71. is almost exactly the same as:
  72.  
  73.   use fields qw(_Foo);
  74.  
  75. with the exception that you can (if you REALLY want to) do something
  76. like this:
  77.  
  78.   use private qw(Foo);
  79.  
  80. Whereas one cannot do this with fields.pm. (Note: This is considered
  81. unwise and private.pm will scream about it if you have Perl's warnings
  82. on.)
  83.  
  84. Additionally, private.pm is a bit clearer in its intent and is not
  85. necessarily implying use of pseudo-hashes.
  86.  
  87.  
  88. =head1 EXAMPLES
  89.  
  90. See L<protected/SYNOPSIS> for an example of use.
  91.  
  92.  
  93. =head1 MUSINGS
  94.  
  95. I fully expect private.pm to eventually mutate into a real pragma
  96. someday when a better formalized OO data system for Perl supplants the
  97. current fledgling pseudo-hashes.
  98.  
  99. =head1 AUTHOR
  100.  
  101. Michae G Schwern <schwern@pobox.com>
  102.  
  103. =head1 SEE ALSO
  104.  
  105. L<public>, L<protected>, L<fields>, L<base>, L<Class::Fields>
  106.  
  107. =cut
  108.