Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

doc patches and minor revelations

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


jarom at jaromsmith

May 29, 2009, 11:43 AM

Post #1 of 3 (621 views)
Permalink
doc patches and minor revelations

Tomas Doran wrote:
> Jarom Smith wrote:
>> Hello Catalysters:
>>
>> First of all, a thousand apologies if this is a FAQ (and if it is,
>> please point me in the right direction). I have been programming in
>> Perl for a while but I freely admit there's a lot I don't know, which
>> is why I am here. I have completed the Catalyst tutorial, purchased
>> the book (which I am in the process of reading/completing) and I have
>> scrutinized all sorts of web pages trying to figure this out, but have
>> so far been unsuccessful.
>
> Right! Your question has been answered in the rest of the thread, which
> is great.
>
> Please please please submit a doc patch which contains the appropriate
> pointers to the info you want, where you tried to find that info...
>
> This is obvious to anyone who knows DBIC, but obviously not clear to
> beginners. Please point out where we should document it so that the next
> person doesn't struggle!
>
> Thanks in advance.
> t0m
>

Hi t0m:

Pretend I'm a complete ignoramus... (that shouldn't be too hard, LOL)
If I were to want to submit a "doc patch", how would I go about doing it
and what exactly would I be submitting?

One revelation I had recently which I don't think has been mentioned
anywhere (at least not that I recall) is that when using DBIC and
Catalyst, *everything* is treated as a scalar. (is this a true
statement?) So in other words,

my $people = $c->model('AddressDB::People')

instead of

my @people = $c->model('AddressDB::People')

This hit me while reading p. 41 of the book. I'm not even totally sure
it's correct but things seem to work better when I adopt this
view-point, so it probably is correct. It kind of makes sense, because
the Catalyst stash stores things using scalars (strings) as keys, so if
you just think of everything as a scalar (which could be a ref to an
array or hash) then things become slightly less confusing. At least,
that's my current understanding. I am still very much muddling my way
through all this stuff.

What I haven't figured out (yet) is why it is necessary for me to cast
some things to array, whereas other times it works without casting to
array. I'm sorry, I don't have a specific code example. I'm still
working through the book and studying CPAN documentation pages
furiously. I'll get it eventually.


jarom smith
tech go-to guy

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


romkey at apocalypse

May 29, 2009, 8:47 PM

Post #2 of 3 (561 views)
Permalink
Re: doc patches and minor revelations [In reply to]

On May 29, 2009, at 2:43 PM, Jarom Smith wrote:
> One revelation I had recently which I don't think has been mentioned
> anywhere (at least not that I recall) is that when using DBIC and
> Catalyst, *everything* is treated as a scalar. (is this a true
> statement?) So in other words,
>
> my $people = $c->model('AddressDB::People')
>
> instead of
>
> my @people = $c->model('AddressDB::People')


Assuming that AddressDB::People is a DBIx::Class-based model, then

my $people = $c->model('AddressDB::People')

will get you a DBIx::Class::ResultSet object, which is an object. You
can then use that object to iterate over the resultset or chain
another search on it.

my @people = $c->model('AddressDB::People')

will get you an array of row objects, which are the values returned by
iterating over the resultset. It's the equivalent of $c-
>model('AddressBookDB::People')->all();

Catalyst just provides a thin wrapper around the model, so this
doesn't really have anything to do with Catalyst and is more the
behaviour of DBIx::Class.
- john romkey
http://www.romkey.com/


_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


bobtfish at bobtfish

May 30, 2009, 7:34 AM

Post #3 of 3 (555 views)
Permalink
Re: doc patches and minor revelations [In reply to]

On 29 May 2009, at 19:43, Jarom Smith wrote:
>
> Pretend I'm a complete ignoramus... (that shouldn't be too hard,
> LOL) If I were to want to submit a "doc patch", how would I go
> about doing it and what exactly would I be submitting?
>

Right, so there are two things we want:

1) Documenting the answer to your question
2) Making that answer easy to find.

So lets go back in time a little:

On 27 May 2009, at 17:59, Jarom Smith wrote:
> In a Catalyst context, where do I put these kinds of "helper" DB
> methods and how do I access them? (both from within a Catalyst app,
> as well as from the command-line like in a Cron job or
> whatever...) Some actual specific examples would be great. I'm
> sure there is a way, and I'm guessing it involves the model somehow
> (possibly by creating a new model class?) but I haven't been able
> to figure it out yet. I tried adding methods to the classes
> created by Catalyst/DBIC in the Schema/Result directory, but
> gradually it dawned on me that methods placed here are only dealing
> with a single entity of that type. To go back to Java-speak, it
> seems like the stuff in Schema/Result are DTO methods; what I'm
> trying to figure out is how/where to put the DAO methods.

So I guess the most obvious place for this doc would be in Catalyst-
Model-DBIC-Schema - or at least, the documentation there should point
you in the right direction!

Are there any other significant places you looked for documentation
where it should also be mentioned? (You know - you just searched!)

And I guess that some of this is already documented in
DBIx::Class::Schema::Loader.. So go read the documentation around
there, and make a call about what should be added to the
documentation there (if anything), what should be added in
Catalyst::Model::DBIC::Schema, and any other places you think you
should link it from..

Then check the relevant projects out of subversion:

http://dev.catalyst.perl.org/repos/Catalyst/trunk/Catalyst-Model-DBIC-
Schema/
http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class-Schema-Loader/
http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Manual/5.80/trunk/

Are the things I guess you may want to be patching.

Add some POD as you think is relevant (and use pod2text and/or
pod2html to check it looks ok), make sure the tests still pass (as
they'll test the pod structure for you), then when you're happy, svn
diff and attach the diff to an email..

Someone will then review and apply, or send you some comments back.
If you do this more than a couple of times, someone will hand you a
commit bit so you can just commit directly.

Note the patch to DBIx-Class-Schema-Loader (if you think one is
appropriate) is best sent to the dbic list.

> One revelation I had recently which I don't think has been
> mentioned anywhere (at least not that I recall) is that when using
> DBIC and Catalyst, *everything* is treated as a scalar. (is this a
> true statement?) So in other words,
>
> my $people = $c->model('AddressDB::People')
>
> instead of
>
> my @people = $c->model('AddressDB::People')

Erm, I think you're a bit confused.

When you ask for: my $people = $c->model('AddressDB::People'), then
you get an instance of a ResultSet (i.e. a blessed scalar). This
doesn't hit the DB with a query.

To give you a list back, there have to be things in the list - ergo
you need to go to the db.

my @people = $c->model('AddressDB::People')->all will do this for
you, but beware, this will suck your entire table into RAM...

> This hit me while reading p. 41 of the book. I'm not even totally
> sure it's correct but things seem to work better when I adopt this
> view-point, so it probably is correct. It kind of makes sense,
> because the Catalyst stash stores things using scalars (strings) as
> keys, so if you just think of everything as a scalar (which could
> be a ref to an array or hash) then things become slightly less
> confusing. At least, that's my current understanding. I am still
> very much muddling my way through all this stuff.

Erm, it's up to the specific method invoked what it wants to return.

Some methods implicitly behave differently when called in list or
scalar context, some don't.

That's just perl.

Cheers
t0m

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.