Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hello SergioQ,

Your question is not very clear to me. What do you mean with: "messy blessed text messes"? I searched for something in your recent posts, quickly, I cant find something relevant.

You got good replies (see LanX's one). As he said bless is used to add something like a flag to a reference. The flag says: I'm not from here. I come from Whatever::Package so see there to see how I behave. When some method of this blessed reference is called (a method is simple sub) the first parameter received will be the object itself, generally named $self but just as convention.

A full minimalist example

use strict; use warnings; # usually this is defined inside a perl module # at ./Whatever/Package.pm package Whatever::Package; # this is the constructor. generally called new but is not a rule sub new{ # we will receive the class name as first argument my $class = shift; # and just need to return a reference (an anonymous hash {} in thi +s case) blessed into $class return bless {}, $class; } sub first { my $self = shift; print "We are inside package ",__PACKAGE__, " we received \$self because it is blessed into ",ref $sel +f,"\n"; } # usually this is defined inside a perl module # at ./Another/Example/Package.pm package Another::Example::Package; # note the same NAME for the sub sub first { my $self = shift; print "This method will no be called unless the object is blessed +into Another::Example::Package"; } # usually the script will use Whatever::Package (defined inside a perl + module ./Whatever/Package.pm) # but we can merely switch back to the default package 'main' package main; # again a sub with the same name sub first{ print "We are inside package ",__PACKAGE__," I'm not a method but +a bare lone sub\n"; } # test the local sub first(); # let 'instanciate' an object of the Whatever::Package class my $obj = Whatever::Package->new(); print "\$obj is now a blessed reference. It is blessed into ",ref $obj +,"\n"; # above we have 3 subs named first. Which one will be called? $obj->first();

Start with the standard documentation. See package too.

If you can get a copy of the old but valid Perl CookBook read:

  • Chapter 11: References and Records
  • Chapter 12: Packages, Libraries, and Modules
  • Chapter 13: Classes, Objects, and Ties

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

    In reply to Re: Where can I learn more about blessed data? -- a basic example by Discipulus
    in thread Where can I learn more about blessed data? by SergioQ

    Title:
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post; it's "PerlMonks-approved HTML":



    • Are you posting in the right place? Check out Where do I post X? to know for sure.
    • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
      <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
    • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
    • Want more info? How to link or How to display code and escape characters are good places to start.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (4)
    As of 2024-03-29 10:00 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found