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 / public.pm < prev    next >
Encoding:
Perl POD Document  |  2000-12-13  |  2.5 KB  |  117 lines

  1. package public;
  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.         if( $field =~ /^_/ ) {
  19.             require Carp;
  20.             Carp::carp("Use of leading underscores to name public data ",
  21.                        "fields is considered unwise.") if $^W;
  22.         }
  23.     }
  24.     add_fields($pack, PUBLIC, @_);
  25. }
  26.  
  27.  
  28. return <<TIP
  29. Displaying one's member publicly will often get one arrested for
  30. indecent exposure.
  31. TIP
  32.  
  33. __END__
  34. =pod
  35.  
  36. =head1 NAME
  37.  
  38.   public - Add public data members to Perl classes
  39.  
  40.  
  41. =head1 SYNOPSIS
  42.  
  43.   package GI::Joe;
  44.  
  45.   use public qw( Name Rank Serial_Number );
  46.  
  47.   # see the protected man page for an example of use
  48.  
  49.  
  50. =head1 DESCRIPTION
  51.  
  52. =over 4
  53.  
  54. =item I<Public member.> 
  55.  
  56. Externally visible data or functionality.  An attribute or method that
  57. is directly accessable from scopes outside the class.  In Perl, most
  58. members are, by their standard semantics, public.  By convention,
  59. attributes of Perl classes are regarded as private, as are methods
  60. whose names begin with an underscore.
  61.  
  62. From B<"Object Oriented Perl"> by Damian Conway
  63.  
  64. =back
  65.  
  66. public.pm adds a list of keys as public data members to the current
  67. class.  This is useful when using pseudo-hashes as objects, or for
  68. simply imposing a bit more structure on your Perl objects than is
  69. normally expected.  It allows you to use the methods provided in
  70. Class::Fields.
  71.  
  72. Public data members are those pieces of data which are expected to be
  73. regularly accessed by methods, functions and programs outside the
  74. class which owns them.  They are also inherited by any subclasses.
  75.  
  76. public.pm serves a subset of the functionality of fields.pm.
  77.  
  78.   use public qw(Foo);
  79.  
  80. is almost exactly the same as:
  81.  
  82.   use fields qw(Foo);
  83.  
  84. with the exception that you can (if you REALLY want to) do something
  85. like this:
  86.  
  87.   use public qw(_Foo);
  88.  
  89. Whereas one cannot do this with fields.pm. (Note: This is considered
  90. unwise and public.pm will scream about it if you have Perl's warnings
  91. on.)
  92.  
  93. Additionally, public.pm is a bit clearer in its intent and is not
  94. necessarily implying use of pseudo-hashes.
  95.  
  96.  
  97. =head1 EXAMPLE
  98.  
  99. See L<protected/SYNOPSIS> for an example of use.
  100.  
  101. =head1 MUSINGS
  102.  
  103. I fully expect public.pm to eventually mutate into a real pragma
  104. someday when a better formalized OO data system for Perl supplants the
  105. current fledgling pseudo-hashes.
  106.  
  107.  
  108. =head1 AUTHOR
  109.  
  110. Michae G Schwern <schwern@pobox.com>
  111.  
  112. =head1 SEE ALSO
  113.  
  114. L<private>, L<protected>, L<fields>, L<base>, L<Class::Fields>
  115.  
  116. =cut
  117.