Add built local::lib
[catagits/Gitalist.git] / local-lib5 / man / man3 / Moose::Cookbook::Basics::Recipe1.3pm
diff --git a/local-lib5/man/man3/Moose::Cookbook::Basics::Recipe1.3pm b/local-lib5/man/man3/Moose::Cookbook::Basics::Recipe1.3pm
new file mode 100644 (file)
index 0000000..2c77e03
--- /dev/null
@@ -0,0 +1,391 @@
+.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.3
+.\"
+.\" Standard preamble:
+.\" ========================================================================
+.de Sh \" Subsection heading
+.br
+.if t .Sp
+.ne 5
+.PP
+\fB\\$1\fR
+.PP
+..
+.de Sp \" Vertical space (when we can't use .PP)
+.if t .sp .5v
+.if n .sp
+..
+.de Vb \" Begin verbatim text
+.ft CW
+.nf
+.ne \\$1
+..
+.de Ve \" End verbatim text
+.ft R
+.fi
+..
+.\" Set up some character translations and predefined strings.  \*(-- will
+.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
+.\" double quote, and \*(R" will give a right double quote.  | will give a
+.\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used to
+.\" do unbreakable dashes and therefore won't be available.  \*(C` and \*(C'
+.\" expand to `' in nroff, nothing in troff, for use with C<>.
+.tr \(*W-|\(bv\*(Tr
+.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
+.ie n \{\
+.    ds -- \(*W-
+.    ds PI pi
+.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
+.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
+.    ds L" ""
+.    ds R" ""
+.    ds C` ""
+.    ds C' ""
+'br\}
+.el\{\
+.    ds -- \|\(em\|
+.    ds PI \(*p
+.    ds L" ``
+.    ds R" ''
+'br\}
+.\"
+.\" If the F register is turned on, we'll generate index entries on stderr for
+.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
+.\" entries marked with X<> in POD.  Of course, you'll have to process the
+.\" output yourself in some meaningful fashion.
+.if \nF \{\
+.    de IX
+.    tm Index:\\$1\t\\n%\t"\\$2"
+..
+.    nr % 0
+.    rr F
+.\}
+.\"
+.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
+.\" way too many mistakes in technical documents.
+.hy 0
+.if n .na
+.\"
+.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
+.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
+.    \" fudge factors for nroff and troff
+.if n \{\
+.    ds #H 0
+.    ds #V .8m
+.    ds #F .3m
+.    ds #[ \f1
+.    ds #] \fP
+.\}
+.if t \{\
+.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
+.    ds #V .6m
+.    ds #F 0
+.    ds #[ \&
+.    ds #] \&
+.\}
+.    \" simple accents for nroff and troff
+.if n \{\
+.    ds ' \&
+.    ds ` \&
+.    ds ^ \&
+.    ds , \&
+.    ds ~ ~
+.    ds /
+.\}
+.if t \{\
+.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
+.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
+.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
+.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
+.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
+.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
+.\}
+.    \" troff and (daisy-wheel) nroff accents
+.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
+.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
+.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
+.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
+.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
+.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
+.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
+.ds ae a\h'-(\w'a'u*4/10)'e
+.ds Ae A\h'-(\w'A'u*4/10)'E
+.    \" corrections for vroff
+.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
+.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
+.    \" for low resolution devices (crt and lpr)
+.if \n(.H>23 .if \n(.V>19 \
+\{\
+.    ds : e
+.    ds 8 ss
+.    ds o a
+.    ds d- d\h'-1'\(ga
+.    ds D- D\h'-1'\(hy
+.    ds th \o'bp'
+.    ds Th \o'LP'
+.    ds ae ae
+.    ds Ae AE
+.\}
+.rm #[ #] #H #V #F C
+.\" ========================================================================
+.\"
+.IX Title "Moose::Cookbook::Basics::Recipe1 3"
+.TH Moose::Cookbook::Basics::Recipe1 3 "2009-05-01" "perl v5.8.7" "User Contributed Perl Documentation"
+.SH "NAME"
+Moose::Cookbook::Basics::Recipe1 \- The (always classic) \fBPoint\fR example.
+.SH "SYNOPSIS"
+.IX Header "SYNOPSIS"
+.Vb 2
+\&  package Point;
+\&  use Moose;
+.Ve
+.PP
+.Vb 2
+\&  has 'x' => (isa => 'Int', is => 'rw', required => 1);
+\&  has 'y' => (isa => 'Int', is => 'rw', required => 1);
+.Ve
+.PP
+.Vb 5
+\&  sub clear {
+\&      my $self = shift;
+\&      $self\->x(0);
+\&      $self\->y(0);
+\&  }
+.Ve
+.PP
+.Vb 2
+\&  package Point3D;
+\&  use Moose;
+.Ve
+.PP
+.Vb 1
+\&  extends 'Point';
+.Ve
+.PP
+.Vb 1
+\&  has 'z' => (isa => 'Int', is => 'rw', required => 1);
+.Ve
+.PP
+.Vb 4
+\&  after 'clear' => sub {
+\&      my $self = shift;
+\&      $self\->z(0);
+\&  };
+.Ve
+.PP
+.Vb 1
+\&  package main;
+.Ve
+.PP
+.Vb 3
+\&  # hash or hashrefs are ok for the constructor
+\&  my $point1 = Point\->new(x => 5, y => 7);
+\&  my $point2 = Point\->new({x => 5, y => 7});
+.Ve
+.PP
+.Vb 1
+\&  my $point3d = Point3D\->new(x => 5, y => 42, z => \-5);
+.Ve
+.SH "DESCRIPTION"
+.IX Header "DESCRIPTION"
+This is the classic Point example. It is taken directly from the Perl
+6 Apocalypse 12 document, and is similar to the example found in the
+classic K&R C book as well.
+.PP
+As with all Perl 5 classes, a Moose class is defined in a package.
+Moose handles turning on \f(CW\*(C`strict\*(C'\fR and \f(CW\*(C`warnings\*(C'\fR for us, so all we
+need to do is say \f(CW\*(C`use Moose\*(C'\fR, and no kittens will die.
+.PP
+When Moose is loaded, it exports a set of sugar functions into our
+package. This means that we import some functions which serve as Moose
+\&\*(L"keywords\*(R". These aren't real language keywords, they're just Perl
+functions exported into our package.
+.PP
+Moose automatically makes our package a subclass of Moose::Object.
+The Moose::Object class provides us with a constructor that
+respects our attributes, as well other features. See Moose::Object
+for details.
+.PP
+Now, onto the keywords. The first one we see here is \f(CW\*(C`has\*(C'\fR, which
+defines an instance attribute in our class:
+.PP
+.Vb 1
+\&  has 'x' => (isa => 'Int', is => 'rw', required => 1);
+.Ve
+.PP
+This will create an attribute named \f(CW\*(C`x\*(C'\fR. The \f(CW\*(C`isa\*(C'\fR parameter says
+that we expect the value stored in this attribute to pass the type
+constraint for \f(CW\*(C`Int\*(C'\fR (1). The accessor generated for this attribute
+will be read\-write.
+.PP
+The \f(CW\*(C`requires => 1\*(C'\fR parameter means that this attribute must be
+provided when a new object is created. A point object without
+coordinates doesn't make much sense, so we don't allow it.
+.PP
+We have defined our attributes; next we define our methods. In Moose,
+as with regular Perl 5 \s-1OO\s0, a method is just a subroutine defined
+within the package:
+.PP
+.Vb 5
+\&  sub clear {
+\&      my $self = shift;
+\&      $self\->x(0);
+\&      $self\->y(0);
+\&  }
+.Ve
+.PP
+That concludes the \fBPoint\fR class.
+.PP
+Next we have a subclass of \fBPoint\fR, \fBPoint3D\fR. To declare our
+superclass, we use the Moose keyword \f(CW\*(C`extends\*(C'\fR:
+.PP
+.Vb 1
+\&  extends 'Point';
+.Ve
+.PP
+The \f(CW\*(C`extends\*(C'\fR keyword works much like \f(CW\*(C`use base\*(C'\fR. First, it will
+attempt to load your class if needed. However, unlike \f(CW\*(C`base\*(C'\fR, the
+\&\f(CW\*(C`extends\*(C'\fR keyword will \fIoverwrite\fR any previous values in your
+package's \f(CW@ISA\fR, where \f(CW\*(C`use base\*(C'\fR will \f(CW\*(C`push\*(C'\fR values onto the
+package's \f(CW@ISA\fR.
+.PP
+It is my opinion that the behavior of \f(CW\*(C`extends\*(C'\fR is more intuitive.
+(2).
+.PP
+Next we create a new attribute for \fBPoint3D\fR called \f(CW\*(C`z\*(C'\fR.
+.PP
+.Vb 1
+\&  has 'z' => (isa => 'Int', is => 'rw', required => 1);
+.Ve
+.PP
+This attribute is just like \fBPoint\fR's \f(CW\*(C`x\*(C'\fR and \f(CW\*(C`y\*(C'\fR attributes.
+.PP
+The \f(CW\*(C`after\*(C'\fR keyword demonstrates a Moose feature called \*(L"method
+modifiers\*(R" (or \*(L"advice\*(R" for the \s-1AOP\s0 inclined):
+.PP
+.Vb 4
+\&  after 'clear' => sub {
+\&      my $self = shift;
+\&      $self\->z(0);
+\&  };
+.Ve
+.PP
+When \f(CW\*(C`clear\*(C'\fR is called on a \fBPoint3D\fR object, our modifier method
+gets called as well. Unsurprisingly, the modifier is called \fIafter\fR
+the real method.
+.PP
+In this case, the real \f(CW\*(C`clear\*(C'\fR method is inherited from \fBPoint\fR. Our
+modifier method receives the same arguments as those passed to the
+modified method (just \f(CW$self\fR here).
+.PP
+Of course, using the \f(CW\*(C`after\*(C'\fR modifier is not the only way to
+accomplish this. This \fBis\fR Perl, right? You can get the same results
+with this code:
+.PP
+.Vb 5
+\&  sub clear {
+\&      my $self = shift;
+\&      $self\->SUPER::clear();
+\&      $self\->z(0);
+\&  }
+.Ve
+.PP
+You could also use another Moose method modifier, \f(CW\*(C`override\*(C'\fR:
+.PP
+.Vb 5
+\&  override 'clear' => sub {
+\&      my $self = shift;
+\&      super();
+\&      $self\->z(0);
+\&  };
+.Ve
+.PP
+The \f(CW\*(C`override\*(C'\fR modifier allows you to use the \f(CW\*(C`super\*(C'\fR keyword to
+dispatch to the superclass's method in a very Ruby-ish style.
+.PP
+The choice of whether to use a method modifier, and which one to use,
+is often a question of style as much as functionality.
+.PP
+Since \fBPoint\fR inherits from Moose::Object, it will also inherit
+the default Moose::Object constructor:
+.PP
+.Vb 2
+\&  my $point1 = Point\->new(x => 5, y => 7);
+\&  my $point2 = Point\->new({x => 5, y => 7});
+.Ve
+.PP
+.Vb 1
+\&  my $point3d = Point3D\->new(x => 5, y => 42, z => \-5);
+.Ve
+.PP
+The \f(CW\*(C`new\*(C'\fR constructor accepts a named argument pair for each
+attribute defined by the class, which you can provide as a hash or
+hash reference. In this particular example, the attributes are
+required, and calling \f(CW\*(C`new\*(C'\fR without them will throw an error.
+.PP
+.Vb 1
+\&  my $point = Point\->new( x => 5 ); # no y, kaboom!
+.Ve
+.PP
+From here on, we can use \f(CW$point\fR and \f(CW$point3d\fR just as you would
+any other Perl 5 object. For a more detailed example of what can be
+done, you can refer to the
+\&\fIt/000_recipes/moose_cookbook_basics_recipe1.t\fR test file.
+.Sh "Moose Objects are Just Hashrefs"
+.IX Subsection "Moose Objects are Just Hashrefs"
+While this all may appear rather magical, it's important to realize
+that Moose objects are just hash references under the hood (3). For
+example, you could pass \f(CW$self\fR to \f(CW\*(C`Data::Dumper\*(C'\fR and you'd get
+exactly what you'd expect.
+.PP
+You could even poke around inside the object's data structure, but
+that is strongly discouraged.
+.PP
+The fact that Moose objects are hashrefs means it is easy to use Moose
+to extend non-Moose classes, as long as they too are hash
+references. If you want to extend a non-hashref class, check out
+\&\f(CW\*(C`MooseX::InsideOut\*(C'\fR.
+.SH "CONCLUSION"
+.IX Header "CONCLUSION"
+This recipe demonstrates some basic Moose concepts, attributes,
+subclassing, and a simple method modifier.
+.SH "FOOTNOTES"
+.IX Header "FOOTNOTES"
+.IP "(1)" 4
+.IX Item "(1)"
+Moose provides a number of builtin type constraints are provided by,
+of which \f(CW\*(C`Int\*(C'\fR is one. For more information on the type constraint
+system, see Moose::Util::TypeConstraints.
+.IP "(2)" 4
+.IX Item "(2)"
+The \f(CW\*(C`extends\*(C'\fR keyword support multiple inheritance. Simply pass all
+of your superclasses to \f(CW\*(C`extends\*(C'\fR as a list:
+.Sp
+.Vb 1
+\&  extends 'Foo', 'Bar', 'Baz';
+.Ve
+.IP "(3)" 4
+.IX Item "(3)"
+Moose supports using instance structures other than blessed hash
+references (such as in a glob reference \- see
+MooseX::GlobRef::Object).
+.SH "SEE ALSO"
+.IX Header "SEE ALSO"
+.IP "Method Modifiers" 4
+.IX Item "Method Modifiers"
+The concept of method modifiers is directly ripped off from \s-1CLOS\s0. A
+great explanation of them can be found by following this link.
+.Sp
+<http://www.gigamonkeys.com/book/object\-reorientation\-generic\-functions.html>
+.SH "AUTHORS"
+.IX Header "AUTHORS"
+Stevan Little <stevan@iinteractive.com>
+.PP
+Dave Rolsky <autarch@urth.org>
+.SH "COPYRIGHT AND LICENSE"
+.IX Header "COPYRIGHT AND LICENSE"
+Copyright 2006\-2009 by Infinity Interactive, Inc.
+.PP
+<http://www.iinteractive.com>
+.PP
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.