/[Frey]/trunk/lib/Frey/Web/Item.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Frey/Web/Item.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 147 - (show annotations)
Wed Jul 16 21:21:13 2008 UTC (14 years, 6 months ago) by dpavlin
File size: 2374 byte(s)
don't call exec_callbacks if we can't do it
1 package Frey::Web::Item;
2
3 use Data::Dump qw/dump/;
4 use Carp qw/carp/;
5
6 use Moose;
7 extends 'Frey';
8 with 'Frey::Web::Field';
9 with 'Frey::Web::Layout';
10 #with 'BonusTypes';
11
12 use Moose::Util::TypeConstraints;
13
14 enum 'Render_as' => qw( view edit none );
15 has render_as => ( is => 'rw', isa => 'Render_as', required => 1, default => 'view' );
16
17 has fey => (
18 is => 'rw',
19 isa => 'Object', # FIXME Strix::User?
20 # required => 1, # XXX if we require it we can't have Add form
21 );
22
23 has fey_class => (
24 is => 'rw',
25 isa => 'Str',
26 required => 1,
27 );
28
29 has 'display_columns' => (
30 is => 'rw',
31 isa => 'ArrayRef[Str]',
32 lazy_build => 1,
33 );
34
35 sub set_from_hash {
36 my ($self, $f) = @_;
37 my $attrmap = $self->fey->meta->get_attribute_map if $self->fey;
38 my $hash;
39 foreach my $name ( @{ $self->display_columns } ) {
40 my $field_name = $self->field_name($name);
41 if(defined $f->{$field_name}) {
42 $hash->{ $name } = $f->{$field_name};
43
44 if ( defined $attrmap->{$name} ) {
45 my $writer = $attrmap->{$name}->get_write_method;
46 $self->fey->$writer($f->{$field_name});
47 } else {
48 warn "can't store value back into fey->$name";
49 }
50 }
51 }
52 warn "# set_from_hash ", $self->uuid," produced hash = ",dump( $hash ) if $hash;
53 return $hash;
54 }
55
56 sub main {
57 my ( $self ) = @_;
58
59 warn "# item ",$self->uuid, " fey = ",dump( $self->fey ) if $self->debug;
60
61 while(1) {
62 my $out;
63 if ( $self->render_as eq 'edit' ) {
64 $out .= $self->render_edit;
65 } elsif ( $self->render_as eq 'view' ) {
66 $out .= $self->render_view;
67 } else {
68 warn "no renderer ",dump( $self->render_as ), " skipping...";
69 }
70
71 warn $@ if $@;
72 warn ">>> ",length($out),"\n";
73 my $f = $self->next($out);
74 $self->set_from_hash($f);
75 $self->exec_callbacks($f) if $self->can('exec_callbacks');
76 }
77 };
78
79 sub field_value {
80 my ( $self, $name ) = @_;
81 my $val = '';
82 $val = $self->fey->$name if $self->fey && $self->fey->can($name);
83 return $val;
84 }
85
86 sub field_label {
87 my ( $self, $name ) = @_;
88 my $label = ucfirst($name);
89 return $label;
90 }
91
92 sub _build_display_columns {
93 my $self = shift;
94
95 my $m = $self->fey_class->meta;
96
97 my @cols;
98
99 foreach ( $m->get_attribute_list ) {
100 my $attr = $m->get_attribute( $_ );
101 warn "_build_display_columns $_\n" if $self->debug;
102 # FIXME primary key would have to be read-only!
103 push @cols, $_;
104 }
105
106 warn "## display_columns ",dump( @cols ) if $self->debug;
107
108 return \@cols;
109 }
110
111 1;

  ViewVC Help
Powered by ViewVC 1.1.26